See what has been deleted by Collections.retainAll ()?

I have two sets, let's call them s1 and s2. S1 is a HashSet < String >; S2 is a collection < String >, as is the set of keys for a hash table.

I want to call s2.retainAll (s1). This removes all mappings of the HashMap which keys are not in s1. However, I would like to know what has been deleted. retainAll() returns a boolean value indicating whether the s2 has been changed by the call. I would like to know exactly how it has been modified.

Note that I don't expect to be able to use retainAll(); I'm guessing that the solution will involve iterating over the two sets. I just wonder what is the most effective method of this accomplishin.

Thanks to anyone who can suggest anything.

Published by: 803559 on May 13, 2011 21:51
Set s2Copy = new HashSet(s2);
s2.retainAll(s1);
s2Copy.removeAll(s2);

At this point, s2Copy contains the items that you are looking for.

Tags: Java

Similar Questions

Maybe you are looking for

  • Satellite Pro A100 and load problems

    Hello everyone. New Member here. Got a huge problem with my laptop. I have a satellite pro A100-830. Part number: PSAACE-00W002EN. About 2 years ago I can run on the current system. But it will not work on battery. I just bought a new battery and it

  • How to print 4 different pictures on one page with Windows Photo Gallery?

    Could not find any way to add different photo once I chose one to print (so I can print 4 different photos on A4 only once.)

  • ASA or PIX

    I have to choose between a pix501 or an asa5505-k9 for a firewall on a small office. Which one is recommended. Is the ASA the future replacemente for the PIX? Thank you Osvaldo U.

  • How to download wizard 101 on a surface

    I just got mine and he said it's just like a computer and I was able to download wizard 101 but it won't let me not all boards

  • Lag function

    Oracle version: 11.0.2.0.2.0Dear allI have a question where I am using tables Tab1 and Tab2Struncture of tab1 isStore_no NUMBER,Sell_date DATESell quantity number,number of item_noto tab2Number of Item_nodate date1,number of item_priceI need know the