I have a Map<String, ArrayList> and a Set<String>. Is there a way to “intersect” the keys of the map with the set of strings such that only the pairs with the given key remain, without iterating over the entire map? My main concern is performance and re-inventing the wheel on something that can be done more elegantly.
I have a Map<String, ArrayList> and a Set<String> . Is there a way to
Share
Just do:
As per the javadoc, the changes in the key set are reflected back in the map.
Here’s a demo: