CopyOnWriteArraySet - isEmpty, size and clear 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[]) {
Set<String> copyOnWriteArraySet = new CopyOnWriteArraySet<String>();
System.out.println("--------add element ");
copyOnWriteArraySet.add("ankit");
copyOnWriteArraySet.add("mittal");
copyOnWriteArraySet.add("javaMadeSoEasy");
System.out.println("copyOnWriteArraySet = "+copyOnWriteArraySet);
System.out.println("copyOnWriteArraySet.isEmpty() = "+copyOnWriteArraySet.isEmpty());
System.out.println("\n--------clear list - remove all elements from set");
copyOnWriteArraySet.clear();
System.out.println("copyOnWriteArraySet.isEmpty() = "+copyOnWriteArraySet.isEmpty());
System.out.println("copyOnWriteArraySet = "+copyOnWriteArraySet);
}
}
/*OUTPUT
--------add element
copyOnWriteArraySet = [ankit, mittal, javaMadeSoEasy]
copyOnWriteArraySet.isEmpty() = false
--------clear list - remove all elements from set
copyOnWriteArraySet.isEmpty() = true
copyOnWriteArraySet = []
*/
|
Labels:
Collection programs
Core Java