Iterating a CopyOnWriteArrayList never throws ConcurrentModificationException because the iterator walks a snapshot of the array taken when it was created. Elements added afterwards, even from inside the loop, simply do not appear in that iteration.
CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>(List.of("a", "b", "c"));
List<String> seen = new ArrayList<>();
for (String s : list) {
seen.add(s);
if (s.equals("a")) list.add("d");
}
System.out.println("Iterated snapshot: " + seen);
System.out.println("List after mutation during iteration: " + list);
Iterated snapshot: [a, b, c]
List after mutation during iteration: [a, b, c, d]
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27