The following example demonstrates how to use the max() and min() methods of the Collections class to obtain the maximum and minimum values in the List:
/* author by w3cschool.cc Main.java */ import java.util.*; public class Main { public static void main(String[] args) { List list = Arrays.asList("one Two three Four five six one three Four".split(" ")); System.out.println(list); System.out.println("最大值: " + Collections.max(list)); System.out.println("最小值: " + Collections.min(list)); } }
The output result of the above code is:
[one, Two, three, Four, five, six, one, three, Four] 最大值: three 最小值: Four
The above is a Java example - finding the maximum and minimum values in the List. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!