import java.util.Set;
import java.util.TreeSet;
public class RemoveSet {
public static void main(String[] args) {
Set<String> ts = new TreeSet<String>();
ts.add("mumbai");
ts.add("delhi");
ts.add("kolkata");
ts.add("chandigarh");
ts.add("dehradun");
// print treeset
System.out.println("before remove treeset is = "+ts );
Set<String> set = new TreeSet<String>();
set.add("mumbai");
set.add("DELHI");
set.add("PHP");
System.out.println("set is = "+set);
/*
* Removes from this set all of its elements
* that are contained in the specified collection
*/
ts.removeAll(set);
System.out.println("after remove set from treeset ts"+ ts);
}
}
Output:
before remove treeset is = [chandigarh, dehradun, delhi, kolkata, mumbai]
set is = [DELHI, PHP, mumbai]
after remove set from treeset ts[chandigarh, dehradun, delhi, kolkata]
No comments:
Post a Comment