Machine-translated by Google. Questions are authored in English.
Top

Discussion

Iterating a CopyOnWriteArrayList - which of the following is true?

  • A.An iterator from CopyOnWriteArrayList blocks writers until iteration finishes.
  • B.CopyOnWriteArrayList copies the list on every read.
  • C.An iterator from CopyOnWriteArrayList reflects a snapshot and never throws ConcurrentModificationException.
  • D.An iterator from CopyOnWriteArrayList throws ConcurrentModificationException on any concurrent write.

Answer: C

The iterator holds the array as it was when iteration began, so concurrent modifications are invisible to it and cannot invalidate it. The cost is on the write side, which copies the whole array, making the class suitable for read-mostly data such as listener lists.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.