Name

CopyOnWriteArraySet<E>

Synopsis

This class is a threadsafe java.util.Set implementation based on the CopyOnWriteArrayList class. Because the data structure is array-based, the contains( ) method is O(n); this means that this class is suitable only for relatively small sets. Because the data structure uses copy-on-write, the class is best suited to cases where read operations and traversals greatly outnumber update operations. Iteration over the members of the set is efficient, and the Iterator returned by iterator( ) never throws ConcurrentModificationException. The remove( ) method of the iterator throws UnsupportedOperationException. See also CopyOnWriteArrayList.

java.util.concurrent.CopyOnWriteArraySet<E>

Figure 16-79. java.util.concurrent.CopyOnWriteArraySet<E>

public class CopyOnWriteArraySet<E> extends java.util.AbstractSet<E> implements Serializable {
// Public Constructors
     public CopyOnWriteArraySet( );  
     public CopyOnWriteArraySet(java.util.Collection<? extends E> c);  
// Methods Implementing Set
     public boolean add(E o);  
     public boolean addAll(java.util.Collection<? extends E> c);  
     public void clear( );  
     public boolean contains(Object o);  
     public boolean containsAll(java.util.Collection<?> c);  
     public boolean isEmpty( );                          default:true
     public java.util.Iterator<E> iterator( );  
     public boolean remove(Object o);  
     public boolean retainAll(java.util.Collection<?> c);  
     public int size( );  
     public Object[ ] toArray( ); public <T> ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.