Map<String, Integer> map = new HashMap<String, Integer>;
...
Map<String, Integer> sortedMap = sortByValue(map);
Integer max = sortedMap.keySet().iterator().next();
John->100
Mary->50
Mike-> 2
...
While there are some Map
implementations that have a notion of order, this is not part of the Map contract. In particular HashMap
does not guarantee any ordering of the entries.
It depends what you did here in sortByValue
and if the map that is returned preseves some order.