Java当中对集合进行排序
1.普通排序
//顺序
list=list.stream().sorted().collect(Collectors.toList());
list.stream().sorted(Comparator.comparing(Student::getAge))
//倒序
list.stream().sorted(Comparator.reverseOrder())
list.stream().sorted(Comparator.comparing(Student::getAge).reversed())
2.含空值排序
//含空值的正序(升序)排序(按创建时间排序)
list=list.stream().sorted(Comparator.comparing(l -> l.getCreateTime(), Comparator.nullsFirst(Date::compareTo))).collect(Collectors.toList());
3.不用Stream
// 正序
list.sort(Comparator.comparing(Integer::intValue));
list.sort(Comparator.comparing(Student::getAge));
// 倒序
list.sort(Comparator.comparing(Integer::intValue).reversed());
list.sort(Comparator.comparing(Student::getAge).reversed());