[thelist] Java: Sorted Map by value ?

Lee Kowalkowski lee.kowalkowski at googlemail.com
Wed Sep 3 15:51:39 CDT 2008

2008/9/3 Bojan Tesanovic <btesanovic at gmail.com>:
> just trying to do some simple thing in Java and I can't find
> Container (Map) in java.util classes that maintains value sorting and
> allows duplicate values though its easy to do it in PHP
> What I found so far is TreeMap that sorts keys though I don't need it :)

Hi Bojan, a TreeMap will sort using your values on entry if you
provide your own Comparator when you construct it.

However, a Map cannot contain duplicates, you should probably use a
List.  Lists can be sorted using the static method
Collections.sort(List, Comparator).


More information about the thelist mailing list