What is `CopyOnWriteArrayList` and when should it be used?
`CopyOnWriteArrayList` is a thread-safe list implementation where each modification creates a copy of the underlying array, making it suitable for cases where reads vastly outnumber writes.
Exactly! `CopyOnWriteArrayList` is ideal for scenarios with frequent reads and fewer writes, ensuring thread safety without external synchronization.
Can you explain what happens internally when you call methods like `add()` or `remove()` on a `CopyOnWriteArrayList`?