1.Stream流sorted
正序:
List<Person> collect = personList
.stream()
.sorted(Comparator.comparing(Person::getUploadTime))
.collect(Collectors.toList());
倒序:
List<Person> collect = personList
.stream()
.sorted((p1, p2) -> p2.getUploadTime().compareTo(p1.getUploadTime()))
.collect(Collectors.toList());
2.List sort,直接给List排序
personList.sort(Comparator.comparing(Person::getUploadTime));
倒序:
personList.sort((p1, p2) -> p2.getUploadTime().compareTo(p1.getUploadTime()));