CopyOnWriteArrayList iterator behaviour?
It seems that if you create an
Iterator
on CopyOnWriteArrayList
, then they initially point to the same Array object (@786 in this case).
But as you continue iterating through it and, say, remove an element, then the CopyOnWriteArrayList
becomes a new instance (now pointing to @785) with the element removed, whereas the Iterator
still keeps the old Array (@786).
If I understand it correctly, then this is why CopyOnWriteArrayList
allows modification as you iterate through its collection, whereas normally its not possible due to potential errors happening (skipping over elements as you delete).
Am I right?1 Reply
⌛
This post has been reserved for your question.
Hey @Steadhaven! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.