Java Examples - Find Maximum and Minimum in List
The following example demonstrates how to use the max() and min() methods of the Collections class to obtain the maximum and minimum values in a List:
Main.java file
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("Maximum value:" + Collections.max(list));
System.out.println("Minimum value:" + Collections.min(list));
}
}
The output of running the above code is:
[one, Two, three, Four, five, six, one, three, Four] 最大值: three 最小值: FourOther Extensions
Java Examples