You could insert both the key,value pair and its inverse into your map structure, but would have to convert the Integer to a string:
map.put("theKey", "theValue");
map.put("theValue", "theKey");
Using map.get("theValue") will then return "theKey".
It's a quick and dirty way that I've made constant maps, which will only work for a select few datasets:
- Contains only 1 to 1 pairs
- Set of values is disjoint from the set of keys (1->2, 2->3 breaks it)
If you want to keep <Integer, String>
you could maintain a second <String, Integer>
map to "put" the value -> key pairs.