I am using comparators lambda expression to sort date in long format.
Comparator's comparingLong
method is used to sort list of date objects in long format (milliseconds).
It sorts the dates properly, but the problem is that whenever a null value is encountered in date object, it breaks and throws a null pointer exception.
Can you please help me to avoid this, either by using any check in lambda expression, because I don't know how this check can be used in lamda expression, or is there any other way to avoid this exception?
Below lambda expression is used. How will we impose null check in this, so that all the null date values comes at the end of the list and code does not break?
myList.sort(Comparator.comparingLong(e -> e.getBirthDate().getTime()));