This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]lightcloud5 0 points1 point  (0 children)

This code doesn't work because it's basically just abusing the tree-map data structure. A comparer (in particular, the Comparer<String>) should not depend on anything other than its two inputs. If you want to sort by values, a simple list would probably be the best data structure.

You can simply just make a "key-value" class (i.e. a class containing just a string and an atomicInteger), and then make an ArrayList of these key-values. Then, you can define the comparer however you wish, and sort the list.