Here's the code
package main.basics;
import java.util.ArrayList;
import java.util.List;
public class Collections {
/**
* @param args
*/
public static void main(
String[] args) {
List<String> sampleSet = new ArrayList<String>();
String sequence = new String("a");
String postSequence = new String("b");
sampleSet.add(sequence);
sampleSet.add(postSequence);
System.out.println(sampleSet.size());
for (String element : sampleSet) {
System.out.println("Purging element " + element);
sampleSet.removeAll(java.util.Collections.singleton(element));
}
System.out.println(sampleSet.size());
}
}
---------
OUTPUT
---------
2
Purging element a
1
Can anyone tell me why is the collection not cleared completely?