CopyOnWriteArrayList

public class CopyOnWriteArrayList extends Object
implements List<E> RandomAccess Cloneable Serializable

A thread-safe random-access list.

Read operations (including get(int)) do not block and may overlap with update operations. Reads reflect the results of the most recently completed operations. Aggregate operations like addAll(int, Collection) and clear() are atomic; they never expose an intermediate state.

Iterators of this list never throw ConcurrentModificationException. When an iterator is created, it keeps a copy of the list's contents. It is always safe to iterate this list, but iterations may not reflect the latest state of the list.

Iterators returned by this list and its sub lists cannot modify the underlying list. In particular, remove(), add(E) and set(E) all throw UnsupportedOperationException.

This class offers extended API beyond the List interface. It includes additional overloads for indexed search (indexOf(E, int) and lastIndexOf(E, int)) and methods for conditional adds (addIfAbsent(E) and addAllAbsent(Collection)).

Public Constructor Summary

CopyOnWriteArrayList()
Creates a new empty instance.
CopyOnWriteArrayList(Collection<? extends E> collection)
Creates a new instance containing the elements of collection.
CopyOnWriteArrayList(E[] array)
Creates a new instance containing the elements of array.

Public Method Summary

synchronized boolean
add(E e)
Appends the specified element to the end of this list (optional operation).
synchronized void
add(int index, E e)
Inserts the specified element at t