Я хочу отсортировать список в обратном порядке по полю ZoneDateTime, ограничить количество до 20
public class VisitViewDTO implements Serializable {
private ZonedDateTime visitDate;
private int count;
public ZonedDateTime getVisitDate() {
return visitDate;
}
}
.....
List<VisitViewDTO> visitViewDTOList;
visitViewDTOList.stream().sorted(Comparator.comparing(VisitViewDTO::getVisitDate).reversed()).limit(20).collect(Collectors.toList());
Но получил NPE:
java.lang.NullPointerException: null
at java.time.chrono.ChronoZonedDateTime.compareTo(ChronoZonedDateTime.java:570)
at java.time.chrono.ChronoZonedDateTime.compareTo(ChronoZonedDateTime.java:121)
at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)
at java.util.Collections$ReverseComparator2.compare(Collections.java:5178)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:356)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)