HashMap<String, String> foo = new HashMap<String, String>();
HashMap<String, String> baar = new HashMap<String, String>();
How to remove items found in baar
from foo
?
You can try:
foo.keySet().removeAll(baar.keySet())
Changes to a Map
's keySet()
are reflected in the map itself.
If you want to remove exact mappings (not just based on keys), you can use the same approach with the entrySet()
instead:
foo.entrySet().removeAll(baar.entrySet());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With