What is the best way to check if d1.getDept() and d2.getDept() are null in the following lambda before doing the compare? Should the null check be done before the Collections.sort() or can it be done within the lambda statement?
if (sortBy.contains("Dept")) {
Collections.sort(inventoryVariances, (d1, d2) -> d1.getDept().compareTo(d2.getDept()));
}
I need to ensure the Dept data is not null for each object prior to trying to sort by Dept.