Im using the following code to create a hashmap and then sort the values in the hashmap by using a treemap and a comparator. However, the output is rather unexpected. So any th
Please check the JavaDoc of compare: You do not return the bigger value, but -1 for o1 < o2, 0 for o1 = o2 and 1 for o1 > o2. So you could write:
-1
o1
o2
0
1
@Override public int compare(Object o1, Object o2) { return ((Integer) map.get(o1)).compareTo((Integer) map.get(o2); }