List排序

List排序

//按照某个字段进行正序排序
list.sort((x,y) ->Integer.compare(Integer.valueOf(x.getCourseDuration()),Integer.valueOf(y.getCourseDuration())));
//按照某个字段进行倒序排序
list.sort((x,y) ->Integer.compare(Integer.valueOf(y.getCourseDuration()),Integer.valueOf(x.getCourseDuration())));

//按照时间正序排序
studentList.stream().sorted(Comparator.comparing(Student::getCreateTime)).collect(Collectors.toList());
//按照时间倒序排序
studentList.stream().sorted(Comparator.comparing(Student::getCreateTime).reversed()).collect(Collectors.toList());
posted @ 2023-06-27 09:42  striver-sc  阅读(15)  评论(0编辑  收藏  举报