This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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()
Joined: Aug 30, 2012
Yet its simple. Make use of !equals() i.e. not equals method.