java8的List排序

示例1:从小到大,正序排序

List<Student> sList = studentList.stream().sorted(Comparator.comparing(Student::getId)).collect(Collectors.toList());

示例2:倒序

List<Student> sList = studentList.stream().sorted(Comparator.comparing(Student::getId).reversed()).collect(Collectors.toList());

posted on 2022-05-07 15:40  IT-QI  阅读(1100)  评论(0编辑  收藏  举报