如何在 Java 中查找列表的最小值和最大值
问题描述
如何查找列表的最小值和最大值?
解决方案
以下示例使用 min 和 max 方法查找列表的最小值和最大值。
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("max: " + Collections.max(list));
System.out.println("min: " + Collections.min(list));
}
}
结果
上述代码示例将产生以下结果。
[one, Two, three, Four, five, six, one, three, Four] max: three min: Four
java_collections.html

