I have the following function which should return a map of dates to longs such that you iterate through the entries in reverse chronological order.
counts is a LinkedHashMap, so the entries are stored in the order they were inserted (which is chronological in this case):
public Map<Date, Long> getCountsChronological() {
Map<Date, Long> chronologicalMap =
new TreeMap<Date, Long>(Collections.reverseOrder());
chronologicalMap.putAll(counts);
return chronologicalMap;
}
This function does not work, though it seems in theory, that it should. When I iterate through the map that it returns, I am still getting the entries in chronological order.
Unable to reproduce – works fine for me:
Are you sure you’re not iterating over the original map instead of the returned one?