package devmanuals.com; import java.util.List; import java.util.ArrayList; import java.util.concurrent.*; import java.util.Set; import java.util.Iterator; public class CopyOnWriteArraySetDemo { public static void main(String args[]) { CopyOnWriteArraySet set = new CopyOnWriteArraySet(); set.add("A"); set.add("B"); set.add("C"); set.add("D"); set.add("E"); set.add("F"); System.out.println("Elements of set = " + set); Set s = new ConcurrentSkipListSet(); s.add(1); s.add(2); s.add(3); s.add(4); s.add(5); s.add(6); // addAll() method boolean bol = set.addAll(s); System.out .println("Elements after adding all the elements into one set = " + set); // contains() method boolean bol1 = s.contains(6); System.out.println("Does set 's' contains '6' : " + bol1); // containsAll() method boolean bol2 = set.containsAll(s); System.out.println("Does Set 'set' contains the elements of Set 's' : " + bol2); // equals() method boolean bol3 = set.equals(s); System.out.println("Are the elements of Set 's' and 'set' equals : " + bol3); // isEmpty() method boolean bol4 = set.isEmpty(); System.out.println("Set 'set' is empty : " + bol4); // iterator() method Iterator itr = set.iterator(); System.out.println("Elements of set ="); while (itr.hasNext()) { System.out.println(itr.next()); } // size() method Integer it = set.size(); System.out.println("Size of set = " + it); // remove(0) method boolean bol5 = s.remove(4); System.out.println("Did the element remove from set 's' : " + bol5); // clear() method s.clear(); System.out.println("Elements of the set 's' : " + s); } }