Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Find out what was removed by Collections.retainAll() ?

806562May 14 2011 — edited May 14 2011
I 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
This post has been answered by DrClap on May 14 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 11 2011
Added on May 14 2011
3 comments
268 views