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 exceptionRelated terms
- Java List — The collection interface for an ordered sequence of elements that may contain duplicates, with ArrayList as the usual implementation.
- ConcurrentHashMap — A thread-safe Map whose updates such as merge and compute run atomically per key.
Taught in
- Concurrent Collections And Parallel Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Modules And Concurrency — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep