1.

What Is The Difference Between Arraylist And Copyonwritearraylist In Java?

Answer»

ArrayList is not thread-safe whereas COPYONWRITEARRAYLIST is thread-safe and fit for use in multi-threaded environment.

Iterator returned by ArrayList is fail-fast. Iterator returned by CopyOnWriteArrayList is fail-safe.

Performance WISE ArrayList is faster as it is not synchronized and there is no ADDED BURDEN of thread-safety. CopyOnWriteArrayList is comparatively slower and if there are lots of WRITES by various threads that will degrade the performance of the CopyOnwriteArrayList as there will be copies made per mutation.

ArrayList is not thread-safe whereas CopyOnWriteArrayList is thread-safe and fit for use in multi-threaded environment.

Iterator returned by ArrayList is fail-fast. Iterator returned by CopyOnWriteArrayList is fail-safe.

Performance wise ArrayList is faster as it is not synchronized and there is no added burden of thread-safety. CopyOnWriteArrayList is comparatively slower and if there are lots of writes by various threads that will degrade the performance of the CopyOnwriteArrayList as there will be copies made per mutation.



Discussion

No Comment Found