Find out what was removed by Collections.retainAll() ?
806562May 14 2011 — edited May 14 2011I have two Sets, let's call them s1 and s2. s1 is a HashSet<String>; s2 is a Set<String>, as it is the keyset for a HashMap.
I want to call s2.retainAll(s1). This will remove all the mappings from the HashMap whose keys are not in s1. However, I would like to find out what was removed. retainAll() only returns a boolean value indicating whether s2 was modified by the call. I would like to know exactly how it was modified.
Note that I'm not expecting to be able to use retainAll(); I'm guessing the solution will involve iterating over both sets. I'm simply wondering what is the most efficient method of accomplishin this.
Thanks to anybody who can suggest anything.
Edited by: 803559 on 13-May-2011 21:51