CopyOnWriteArrayList for Concurrent Modification in Java


CopyOnWriteArrayList is a thread-safe variant of ArrayList in which all mutative operations are implemented by making a fresh copy of the underlying array.

Source Code

List list = new CopyOnWriteArrayList(Arrays.asList("a", "b", "c"));
for (String element : list) {
    System.out.println(element);
    list.add("d"); // Modifications do not cause ConcurrentModificationException
}
System.out.println(list);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments