java8 返回集对象合中按照某一个属性排序最大和最小的元素

Student student1 = students.stream().max(Comparator.comparing(a -> a.getAge())).get();
Student student2 = students.stream().min(Comparator.comparing(a -> a.getAge())).get();

 

posted @ 2022-06-21 17:52  WPMA  阅读(199)  评论(0)    收藏  举报