-3

Possible Duplicate:
How to sort a Map<Key, Value> on the values in Java?

Hello can you help me about my sortring problem

HashMap<String, Integer> hm = new HashMap<String, Integer>();
hm.put("Berkan Cetin", 100);
hm.put("Mahmut Koca", 78);
hm.put("Rifat Sarili", 89);
hm.put("Cagdas Polat", 61);
hm.put("Gulay Uygun", 56);

For example, in there if I want to sort by keys I can use TreeMap or else, but I cant find way to sort from biggest to smallest Integer according to values.

Thanks

Community
  • 1
  • 1
  • 5
    Dupe of too many to count; just [search for it](http://stackoverflow.com/search?q=java+map+sort+by+value&submit=search). – vanza Nov 10 '11 at 22:53
  • HashMap has no order. You have to use a collection which does, or not use a Map. e.g. `List>` – Peter Lawrey Nov 10 '11 at 22:56

1 Answers1

1

You can do something like new TreeSet<String>(map.keySet()) to get a sorted set of the keys..

A map itself is not something that you sort.

kgautron
  • 7,915
  • 9
  • 39
  • 60