Tengo dos métodos, el uso de este método para obtener la clave con el valor máximo:
public static Entry<String, Integer> getMaxEntry(Map<String, Integer> map){
Entry<String, Integer> maxEntry = null;
Integer max = Collections.max(map.values());
for(Entry<String, Integer> entry : map.entrySet()) {
Integer value = entry.getValue();
if(null != value && max == value) {
maxEntry = entry;
}
}
return maxEntry;
}
Como ejemplo poniendo la Entrada con el valor máximo usando el método:
Map.Entry<String, Integer> maxEntry = getMaxEntry(map);
Usando Java 8 podemos obtener un objeto que contiene el valor máximo:
Object maxEntry = Collections.max(map.entrySet(), Map.Entry.comparingByValue()).getKey();
System.out.println("maxEntry = " + maxEntry);
@Nishan: No veo cómo eso es un duplicado. –