The title question summarizes it nicely, but assume I am coding in Java and have a HashMap
that looks something like this (it has a lot more entries obviously):
Map<String, Integer> myMap = new HashMap<>();
myMap.put{"a", 1}
myMap.put{"b", 2}
myMap.put{"c", 2}
myMap.put{"d", 3}
Now I don't like entries with the value of 2, so I want to remove them all as effectively as possible, leaving me only with the entries that have value 1 or 3.
It should look as if my map was instead made like this:
Map<String, Integer> myMap = new HashMap<>();
myMap.put{"a", 1}
myMap.put{"d", 3}
As if my 2-valued entries were never there at all!
What are my options for doing this in an effective way?