What\'s the quickest way to remove an element from a Map by value in Java?
Currently I\'m using:
DomainObj valueToRemove = new DomainObj();
S
Here's the one-line solution:
map.values().remove(valueToRemove);
That's probably faster than defining your own iterator, since the JDK collection code has been significantly optimized.
As others have mentioned, a bimap will have faster value removes, though it requires more memory and takes longer to populate. Also, a bimap only works when the values are unique, which may or may not be the case in your code.