使用年龄进行升序排序

//按年龄排序(Integer类型)
List<StudentInfo> studentsSortName = studentList.stream().sorted(Comparator.comparing(StudentInfo::getAge)).collect(Collectors.toList());

使用年龄进行降序排序(使用reversed()方法)

//按年龄排序(Integer类型)
List<StudentInfo> studentsSortName = studentList.stream().sorted(Comparator.comparing(StudentInfo::getAge).reversed()).collect(Collectors.toList());

使用年龄进行降序排序,年龄相同再使用身高升序排序

//按年龄排序(Integer类型)
   List<StudentInfo> studentsSortName = studentList.stream()
        .sorted(Comparator.comparing(StudentInfo::getAge).reversed().thenComparing(StudentInfo::getHeight))
        .collect(Collectors.toList());

多字段排序

//先按姓名升序,姓名相同则按年龄升序。
list = list.sorted(Comparator.comparing(Student::getName).thenComparing(Student::getAge)).collect(Collectors.toList());