Return to site

☕🎓JAVA CERTIFICATION QUESTION: CopyOnWriteArrayList

· java,ocp

Given:

var sList = new CopyOnWriteArrayList();

Which of the following statement is correct?

* The CopyOnWriteArrayList class is not thread-safe and does not prevent interference among concurrent threads.

* The CopyOnWriteArrayList class’s iterator reflects all additions, removals, or changes to the list since the iterator was created.

* The CopyOnWriteArrayList class is a thread-safe variant of ArrayList where all mutative operations are implemented by making a fresh copy of the underlying array.

* Element-changing operations on iterators of CopyOnWriteArrayList, such as remove, set, and add, are supported and do not throw UnsupportedOperationException.

* The CopyOnWriteArrayList class does not allow null elements.

#java #certificationquestion #ocp

https://www.udemy.com/course/ocp-oracle-certified-professional-java-developer-prep/?referralCode=54114F9AD41F127CB99A

Incorrect: The iterator of a CopyOnWriteArrayList does not reflect any additions, removals, or changes to the list since the iterator was created. It provides a snapshot of the list at the time of its creation.

Incorrect: Element-changing operations on iterators of CopyOnWriteArrayList, such as remove, set, and add, are not supported. Attempting to perform these operations will result in an UnsupportedOperationException.

Incorrect: The CopyOnWriteArrayList class does allow null elements. It permits all elements, including null.

https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/concurrent/CopyOnWriteArrayList.html