public class CopyOnWriteArraySet<E>
  Comment     Returned-by     Constructor-argument     Method-argument     Field-type     Type-bound     Links  

A java.util.Set that uses an internal CopyOnWriteArrayList for all of its operations. Thus, it shares the same basic properties:

Sample Usage. The following code sketch uses a copy-on-write set to maintain a set of Handler objects that perform some action upon state updates.

 
 class Handler { void handle(); ... 

 class X {
   private final CopyOnWriteArraySet handlers
     = new CopyOnWriteArraySet();
   public void addHandler(Handler h) { handlers.add(h); }

   private long internalState;
   private synchronized void changeState() { internalState = ...; }

   public void update() {
     changeState();
     for (Handler handler : handlers)
       handler.handle();
   }
 }}

This class is a member of the Java Collections Framework.

extends AbstractSet<E> implements Serializable

Parameters:
<E>    the type of elements held in this collection

See also:
CopyOnWriteArrayList

Since:  1.5