public static void main(String[] args) {
initEmp();
int sum = empList.stream().mapToInt(Employee->Employee.getAge()).sum();
int max = empList.stream().mapToInt(Employee->Employee.getAge()).max().getAsInt();
int min = empList.stream().mapToInt(Employee->Employee.getAge()).min().getAsInt();
double avg = empList.stream().mapToInt(Employee->Employee.getAge()).average().getAsDouble();
System.out.println("最大值:"+max+"\n最小值:"+min+"\n总和:"+sum+"\n平均值:"+avg);
}
Java8获取List集合元素最大、最小、总和、平均值
最新推荐文章于 2024-01-16 15:14:37 发布