List集合用stream取list中对象的某个字段的最大值
student对象的集合:
List<Student> stu = baseMapper.getById(id);
student中有成绩字段,每个学生有各自的成绩:
private String name;
private Integer record;
用stream的max()方法的get()方法返回一个student对象,这个对象的record的值就是list中每个student的最大值。
Student student =
stu.stream.max(Comparator.comparing(Student::getRecord)).get();