Tuesday, September 20, 2011

Difference between ArrayList and CopyOnWriteArrayList

When list value is added dynamically when an Iterator is iterating, we will get an java.util.ConcurrentModificationException.

To avoid, we can go for CopyOnWriteArrayList.
Iterators created by a CopyOnWriteArrayList object cannot change the underlying array.Since, We did not get any java.util.ConcurrentModificationException as CopyOnWriteArrayList keeps a copy of original List.

List values are printing using iterator.

CopyOnWriteArrayList values printing using iterator.

for more understanding, refer URL: http://techvivek.wordpress.com/2009/08/29/difference-between-arraylist-and-copyonwritearraylist/

No comments :

Post a Comment