HasMap1 has keys 100 , 200
HashMap2 has keys 200,300,400,100
I need to remove the elements with keys 300 and 400 which are also in HashMap1 from HashMap2. How to achieve that? I thought of different ways but the problem is even if I separate the duplicates keys how to make sure I remove only those from HashMap2.
Alternatively instead of iterating, you can use the retainAll() method in Set interface. First get the key set of the second map and call retainAll() on it with the first map's keys. Check methods - keySet() and retainAll()