The date compareTo () that you use will work in ascending order.
To take a snapshot, simply change the compareTo () value. You can use one Comparator class that accepts a flag / enum in the constructor that identifies the sort order
public int compare(MyObject lhs, MyObject rhs) { if(SortDirection.Ascending == m_sortDirection) { return lhs.MyDateTime.compareTo(rhs.MyDateTime); } return rhs.MyDateTime.compareTo(lhs.MyDateTime); }
You need to call Collections.sort () to sort the list.
As a side note, I'm not sure why you define your map inside a for loop. I'm not quite sure what your code is trying to do, but I assume that you want to populate the indexed values ββfrom the for loop on the map.
source share