Every example I find is about doing this alphabetically, while I need my elements sorted by date.
My ArrayList contains objects on which one of the datamembers is a
With introduction of Java 1.8, streams are very useful in solving this kind of problems:
Comparator myComparator = (arg1, arg2)
-> {
if(arg1.lt(arg2))
return -1;
else if (arg1.lteq(arg2))
return 0;
else
return 1;
};
ArrayList sortedList = myList
.stream()
.sorted(myComparator)
.collect(Collectors.toCollection(ArrayList::new));