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.
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> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access