CopyOnWriteArraySet - add, contains, remove, size methods program







CopyOnWriteArraySet - add, contains, remove, size methods program.




import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
public class CopyOnWriteArraySetTest {
   public static void main(String args[]) {
          System.out.println("-----1. create Set---");
          Set<String> copyOnWriteArraySet = new CopyOnWriteArraySet<String>();
          System.out.println("\n----- adding elements in Set---");
          copyOnWriteArraySet.add("ankit");
          copyOnWriteArraySet.add("JavaMadeSoEasy");
          System.out.println("copyOnWriteArraySet ="+copyOnWriteArraySet);
         
          System.out.println("\n--------contains element  ");
          System.out.println("copyOnWriteArraySet.contains = "+copyOnWriteArraySet.contains("ankit"));
          System.out.println("\n--------Remove element at 1st index i.e. mittal");
          copyOnWriteArraySet.remove("ankit");
          System.out.println(copyOnWriteArraySet);
          System.out.println("copyOnWriteArraySet ="+copyOnWriteArraySet);
   }
}
/*OUTPUT
-----1. create Set---
----- adding elements in Set---
copyOnWriteArraySet =[ankit, JavaMadeSoEasy]
--------contains element
copyOnWriteArraySet.contains = true
--------Remove element at 1st index i.e. mittal
[JavaMadeSoEasy]
copyOnWriteArraySet =[JavaMadeSoEasy]
*/


RELATED LINKS>


CopyOnWriteArraySet - isEmpty, size and clear methods program


CopyOnWriteArraySet - iterate using iterator, Enumeration and enhanced for loop program


CopyOnWriteArraySet - fail-safe or fail-fast iteration using iterator, Enumeration and enhanced for loop program


eEdit
Must read for you :