I have a HashMap defined like this...
HashMap uniqueNames = new HashMap();
It stor
Most obvious, now allowing for multiple with largest occurrence value:
Integer largestVal = null;
List> largestList = new ArrayList>();
for (Entry i : uniqueNames.entrySet()){
if (largestVal == null || largestVal < i.getValue()){
largestVal = i.getValue();
largestList .clear();
largestList .add(i);
}else if (largestVal == i.getValue()){
largestList .add(i);
}
}
Another option would be to use Guava's BiMap.
BiMap uniqueNames = ...;
List values = Lists.newArrayList(uniqueNames.values());
Collections.sort(values);
String name = uniqueNames.inverse().get(values.get(0));