CopyOnWriteArrayList - isEmpty, size and clear methods program







CopyOnWriteArrayList - isEmpty, size and clear methods program.



import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Copyright (c), AnkitMittal JavaMadeSoEasy.com
*/
public class CopyOnWriteArrayListTest {
   public static void main(String args[]) {
          List<String> copyOnWriteArrayList = new CopyOnWriteArrayList<String>();
          System.out.println("\n--------add element to end of list");
          copyOnWriteArrayList.add("ankit");
          copyOnWriteArrayList.add("mittal");
          copyOnWriteArrayList.add("javaMadeSoEasy");
          System.out.println("copyOnWriteArrayList = "+copyOnWriteArrayList);
          System.out.println("copyOnWriteArrayList.isEmpty() = "+copyOnWriteArrayList.isEmpty());
          System.out.println("\n--------clear list - remove all elements from list");
          copyOnWriteArrayList.clear();
         
          System.out.println("copyOnWriteArrayList.isEmpty() = "+copyOnWriteArrayList.isEmpty());
          System.out.println("copyOnWriteArrayList = "+copyOnWriteArrayList);
         
   }
}
/*OUTPUT
--------add element to end of list
copyOnWriteArrayList = [ankit, mittal, javaMadeSoEasy]
copyOnWriteArrayList.isEmpty() = false
--------clear list - remove all elements from list
copyOnWriteArrayList.isEmpty() = true
copyOnWriteArrayList = []
*/




RELATED LINKS>


CopyOnWriteArrayList - iterate using iterator, listIterator, Enumeration and enhanced for loop


CopyOnWriteArrayList - isEmpty, size and clear methods program



eEdit
Must read for you :