CopyOnWriteArrayList

A thread-safe List that copies its array on every write, so iterators see a snapshot.

In more detail

Iterating while another thread, or the loop itself, adds elements never throws; the iterator keeps walking the array as it was when it started. Writes are expensive, so it suits lists that are read far more often than changed.

Example

for (int n : list) list.add(n); // no exception

Related terms

Taught in

References

Certification courses