I'm trying to sort a list of Product objects by their useby Dates, but some of the objects may have their Date useby = null
What I want to do is sort the list by "useby" Dates, and put all the Objects that has Date useby = null on the bottom or on the top of the list.
public static void sort() {
Collections.sort(list, new Comparator<Product>() {
public int compare(Product o1, Product o2) {
if (o1.getUseDate() == null || o2.getUseDate() == null) {
return 0;
} else {
return o1.getUseDate().compareTo(o2.getUseDate());
}
}
});
}
This is my code and I don't know how to fix this.