I am afraid that with simple java.util.Map implementations you should iterate over the map entries and check each value:
for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue().equals(desiredValue) { keys.add(entry.getKey()); } }
If you need better performance, you can create a parallel mapping of values from key lists. I do not know of any existing collection doing this, but it should not be difficult to implement.
Starting with Java 8, you can use map.forEach:
map.forEach((k,val) -> { if (val.equals(desiredValue) { keys.add(k); } });
source share