Possible Duplicate:
How to sort a Map<Key, Value> on the values in Java?
I have a HashMap as following:
Key Value
A 5
B 3
C 10
D 4
E 1
F 11
I need to find the one with highest value, what do you suggest me to do? should I sort them and get the first one or there is any other faster way?
This is much more easily solved by using a
SortedMapand passing in aComparatorfor the values:Prints out: