13 Feb 2018

Difference between ArrayList and CopyOnWriteArrayList.


ArrayList
CopyOnWriteArrayList
It is not Thread safe .
It is not Thread safe because every update operation will be performed on separate cloned copy.

While one Thread iterating List object, the other Threads are not allowed to modify List otherwise we will get ConcurrentModificationException.
While one Thread iterating List object, the other Threads are allowed to modify List in safe manner and  we will not  get ConcurrentModificationException.

Iterator is Fail-Fast.
Iterator is Fail-Safe.

Iterator of ArrayList can perform remove operation.
Iterator of CopyOnWriteArrayList can  not perform remove operation otherwise we will get RE:UnsupportedOperationException.

Introduced in 1.2 version.
Introduced in 1.5 version.