一:
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));
}
}
输出结果为:
[one, Two, three, Four, five, six, one, three, Four]
最大值: three
最小值: Four
二:
List<Integer> input = new ArrayList<Integer>();
input.add(2);
input.add(3);
input.add(4);
input.add(5);
input.add(6);
input.add(7);
input.add(8);
input.add(9);
input.add(1);
System.out.println(input);
System.out.println("最大值: " + Collections.max(input));
System.out.println("最小值: " + Collections.min(input));
输出结果是:
[2, 3, 4, 5, 6, 7, 8, 9, 1]
最大值: 9
最小值: 1