package devmanuals.com; import java.util.List; import java.util.concurrent.*; import java.util.ListIterator; public class CopyOnWriteArrayListDemo1 { public static void main (String args[]){ CopyOnWriteArrayList list = new CopyOnWriteArrayList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); System.out.println("List of elements = "+list); ListIterator litr = list.listIterator(2); System.out.println("List of elements from the index '2' = "); while(litr.hasNext()){ System.out.println(litr.next()); } list.remove(2); list.remove("D"); System.out.println("Rest elements of list = "+list); CopyOnWriteArrayList list1 = new CopyOnWriteArrayList(); list1.add("A"); list1.add("B"); list1.add("C"); boolean bol= list.retainAll(list1); System.out.println("Is list1 retains elements of list : "+bol); Object obj = list.set(1,"C"); System.out.println(list); CopyOnWriteArrayList list2 = new CopyOnWriteArrayList(); list2.add("A"); list2.add("B"); list2.add("C"); list2.add("D"); list2.add("E"); List l = list2.subList(1, 4); System.out.println("Sublist = "+l); } }