0

I have learned that, in Java, TreeMap<K,V> is a SortedMap that sorts according to its keys or by using a Comparator<? extends K> of the keys.

Are there some other SortedMap like TreeMap<K,V> but can sort using a Comparator<? extends V> of the values instead of the keys?

asinkxcoswt
  • 2,252
  • 5
  • 29
  • 57
  • http://stackoverflow.com/questions/8119366/sorting-hashmap-by-values – stinepike Apr 15 '14 at 06:54
  • Sorting by key allows the implementation to find the key efficiently. If the map was sorted by value, we would need some additional data structure to locate keys in the data structure. It would be possible to look up entries by value, but doing so by key is what we care about. – user2357112 Apr 15 '14 at 06:54
  • It would be so great if we could use a zset port in java from redis... it is a sorted set based on a score (double as value) which uses skip lists for performance. – zenbeni Apr 15 '14 at 09:25

0 Answers0