1. Inclusion in java
Arraylist was added in Java 1.2 version.
CopyOnWriteArrayList was added in Java 1.5 or Java 5.
Arraylist in java is not synchronized thus is not at all thread safe.
CopyOnWriteArrayList is synchronized in nature. Thus it is thread safe and for the same reason only one thread can access the resources in this class at a time.
As arraylist is non-synchronized so it is better performance wise as multiple threads can access the resources of arraylist at the same time simultaneously.
Being synchronized means only one thread can have access to CopyOnWriteArrayList resources thus impacting its performance speed.
Arraylist throws ConcurrentModificationException.
CopyOnWriteArrayList doesnot throw ConcurrentModificationException.
5. Fail fast or fail safe
Arraylist’s iterator and list iterator are fail fast in nature.
CopyOnWriteArrayList iterator are fail safe in nature.
You may also like to read:
- ArrayList vs LinkedList
- ArrayList vs Vector
- Collection vs Collections
- ArrayList vs HashSet
- Iterator vs Enumeration