I have this code, which sorts an array list based on 3 variables
result.sort(Comparator.comparing(FeConsumptionChannelDTO::getMeterName)
.thenComparing(FeConsumptionChannelDTO::getValueTypeSeq)
.thenComparing(Comparator.comparing(FeConsumptionChannelDTO::getValidFrom).reversed())
);
But the last variable, getValidFrom can be null since it is OffsetDateTime. If it is null, it throws a NullPointerException. Is there a way to handle null values sorting this way? Or I have to create my own comparing method?
getValidFrom()so that rather than returning null, it returns aOffsetDateTime. If you want nulls to be low, then return a minimum value.