public static void main(String[] args) { List list = new ArrayList(); list.add(1); list.add(9); list.add(3); list.add(5); list.add(4); System.out.println(list); System.out.println("最大值: " + Collections.max(list)); System.out.println("最小值: " + Collections.min(list)); List<Integer> lists = list; DoubleSummaryStatistics statistics = lists.stream().mapToDouble(Number::doubleValue).summaryStatistics(); System.out.println("最大值:" + statistics.getMax()); System.out.println("最小值:" + statistics.getMin()); System.out.println("平均值:" + statistics.getAverage()); System.out.println("平均值四舍五入:" + Math.round(statistics.getAverage())); System.out.println("求和:" + statistics.getSum()); System.out.println("计数:" + statistics.getCount()); }
list 求最大值,最小值,平均值等 已验证 可用
最新推荐文章于 2024-06-12 10:20:00 发布