- CopyOnWriteArrayList creates a Cloned copy of underlying ArrayList, for every update operation at certain point both will synchronized automatically which is takes care by JVM. Therefore there is no effect for threads which are performing read operation. Therefore thread-safety is not there in ArrayList whereas CopyOnWriteArrayList is thread-safe.
- While Iterating ArrayList object by one thread if other thread try to do modification then we will get Runt-time exception saying ConcurrentModificationException. Where as We won’t get any Exception in the case of CopyOnWriteArrayList.
- ArrayList is introduced in JDK 1.2 whereas CopyOnWriteArrayList is introduced by SUN people in JDK 1.5.
- Iterator of ArrayList can perform remove operation while iteration. But Iterator of CopyOnWriteArrayList cant perform remove operation while iteration, otherwise it will throw run-time exception UnsupportedOperationException.
Below is the implementation of this point.
A B Exception in thread "main" java.lang.UnsupportedOperationException
- Java Collection| Difference between Synchronized ArrayList and CopyOnWriteArrayList
- Difference between ArrayList and HashSet in Java
- Difference between length of Array and size of ArrayList in Java
- ArrayList of ArrayList in Java
- CopyOnWriteArrayList in java
- CopyOnWriteArrayList contains() method in Java
- CopyOnWriteArrayList add() method in Java
- CopyOnWriteArrayList get() method in Java
- CopyOnWriteArrayList hashCode() method in Java
- CopyOnWriteArrayList clear() method in Java
- CopyOnWriteArrayList toString() method in Java
- CopyOnWriteArrayList spliterator() method in Java
- CopyOnWriteArrayList size() method in Java
- CopyOnWriteArrayList listIterator() method in Java
- CopyOnWriteArrayList iterator() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.