This code allows you to sort a List
by date. It makes an assumption that the List
is actually a List<RQEntry>
.
Java allows you to call Collections.sort(list, new SomeComparator())
. The comparator you specify in the second argument contains the code that decides how to order items in the list.
The actual comparison interface is that you need to implement int compare(Object o1, Object o2)
. According to the specification, you need to return 0
if the two objects are the same, a negative value if the first item is ordered before the second item, and a positive value if the second item is ordered before the first.
As an example, if you had a list containing [37, 19]
then calling compare(37, 19)
would return 1
(assuming you want to sort a list of integers in ascending order).