Remove operation on iterator not allowed in CopyOnWriteArrayLIst The 2019 Stack Overflow Developer Survey Results Are InHow do I efficiently iterate over each entry in a Java Map?Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loopWhy doesn't java.util.Set have get(int index)?Iterate through a HashMapWhy don't Java's +=, -=, *=, /= compound assignment operators require casting?Ways to iterate over a list in JavaWhy is executing Java code in comments with certain Unicode characters allowed?Merging list concurrently - Which is better, CopyOnWriteArrayList or ConcurrentLinkedQueue?Difference between Iterator,List iterator and CopyOnWriteArrayListUnsupportedOperationException while iterating over CopyOnWriteArrayList
How was Skylab's orbit inclination chosen?
Unbreakable Formation vs. Cry of the Carnarium
What do the Banks children have against barley water?
Springs with some finite mass
Limit the amount of RAM Mathematica may access?
Can't find the latex code for the ⍎ (down tack jot) symbol
Where to refill my bottle in India?
Time travel alters history but people keep saying nothing's changed
Does duplicating a spell with Wish count as casting that spell?
How can I create a character who can assume the widest possible range of creature sizes?
Idiomatic way to prevent slicing?
Spanish for "widget"
Why is my p-value correlated to difference between means in two sample tests?
How to create dashed lines/arrows in Illustrator
Can the Protection from Evil and Good spell be used on the caster?
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
Are there any other methods to apply to solving simultaneous equations?
Which Sci-Fi work first showed weapon of galactic-scale mass destruction?
Why could you hear an Amstrad CPC working?
A poker game description that does not feel gimmicky
Output the Arecibo Message
What are my rights when I have a Sparpreis ticket but can't board an overcrowded train?
Deadlock Graph and Interpretation, solution to avoid
Why don't Unix/Linux systems traverse through directories until they find the required version of a linked library?
Remove operation on iterator not allowed in CopyOnWriteArrayLIst
The 2019 Stack Overflow Developer Survey Results Are InHow do I efficiently iterate over each entry in a Java Map?Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loopWhy doesn't java.util.Set have get(int index)?Iterate through a HashMapWhy don't Java's +=, -=, *=, /= compound assignment operators require casting?Ways to iterate over a list in JavaWhy is executing Java code in comments with certain Unicode characters allowed?Merging list concurrently - Which is better, CopyOnWriteArrayList or ConcurrentLinkedQueue?Difference between Iterator,List iterator and CopyOnWriteArrayListUnsupportedOperationException while iterating over CopyOnWriteArrayList
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am a beginner in Collections framework and came across this concept in CopyOnWriteArrayList:
the remove() operation on the returned Iterator is not permitted – resulting with UnsupportedOperationException. However the remove() method of the CopyOnWriteArrayList itself is permitted.
I am aware that for each mutation a copy of the underlying list is created but I am not sure why the above scenario is not permitted.Can anyone explain the reason why is this so?
java collections
add a comment |
I am a beginner in Collections framework and came across this concept in CopyOnWriteArrayList:
the remove() operation on the returned Iterator is not permitted – resulting with UnsupportedOperationException. However the remove() method of the CopyOnWriteArrayList itself is permitted.
I am aware that for each mutation a copy of the underlying list is created but I am not sure why the above scenario is not permitted.Can anyone explain the reason why is this so?
java collections
When you create a new iterator, the current copy is used. Modifying that copy will possibly change other iterators that work on the same copy.
– Johannes Kuhn
Mar 22 at 3:07
Wont the same thing happen using the list's own remove method as well?
– ghostrider
Mar 22 at 3:23
1
That is true but List and Iterators are different objects. The list is under no obligation to make sure iterator is consistent while iterator has to make sure it is consistent. If you call remove on the list while the iterator is ongoing, you run the risk of some strange behavior there as well but you are supposed to take care of that.
– Vinay Avasthi
Mar 22 at 3:56
The CopyOnWriteArrayList will take care that the iterator is not affected by it.
– Johannes Kuhn
Mar 22 at 4:22
add a comment |
I am a beginner in Collections framework and came across this concept in CopyOnWriteArrayList:
the remove() operation on the returned Iterator is not permitted – resulting with UnsupportedOperationException. However the remove() method of the CopyOnWriteArrayList itself is permitted.
I am aware that for each mutation a copy of the underlying list is created but I am not sure why the above scenario is not permitted.Can anyone explain the reason why is this so?
java collections
I am a beginner in Collections framework and came across this concept in CopyOnWriteArrayList:
the remove() operation on the returned Iterator is not permitted – resulting with UnsupportedOperationException. However the remove() method of the CopyOnWriteArrayList itself is permitted.
I am aware that for each mutation a copy of the underlying list is created but I am not sure why the above scenario is not permitted.Can anyone explain the reason why is this so?
java collections
java collections
asked Mar 22 at 2:48
ghostriderghostrider
4511517
4511517
When you create a new iterator, the current copy is used. Modifying that copy will possibly change other iterators that work on the same copy.
– Johannes Kuhn
Mar 22 at 3:07
Wont the same thing happen using the list's own remove method as well?
– ghostrider
Mar 22 at 3:23
1
That is true but List and Iterators are different objects. The list is under no obligation to make sure iterator is consistent while iterator has to make sure it is consistent. If you call remove on the list while the iterator is ongoing, you run the risk of some strange behavior there as well but you are supposed to take care of that.
– Vinay Avasthi
Mar 22 at 3:56
The CopyOnWriteArrayList will take care that the iterator is not affected by it.
– Johannes Kuhn
Mar 22 at 4:22
add a comment |
When you create a new iterator, the current copy is used. Modifying that copy will possibly change other iterators that work on the same copy.
– Johannes Kuhn
Mar 22 at 3:07
Wont the same thing happen using the list's own remove method as well?
– ghostrider
Mar 22 at 3:23
1
That is true but List and Iterators are different objects. The list is under no obligation to make sure iterator is consistent while iterator has to make sure it is consistent. If you call remove on the list while the iterator is ongoing, you run the risk of some strange behavior there as well but you are supposed to take care of that.
– Vinay Avasthi
Mar 22 at 3:56
The CopyOnWriteArrayList will take care that the iterator is not affected by it.
– Johannes Kuhn
Mar 22 at 4:22
When you create a new iterator, the current copy is used. Modifying that copy will possibly change other iterators that work on the same copy.
– Johannes Kuhn
Mar 22 at 3:07
When you create a new iterator, the current copy is used. Modifying that copy will possibly change other iterators that work on the same copy.
– Johannes Kuhn
Mar 22 at 3:07
Wont the same thing happen using the list's own remove method as well?
– ghostrider
Mar 22 at 3:23
Wont the same thing happen using the list's own remove method as well?
– ghostrider
Mar 22 at 3:23
1
1
That is true but List and Iterators are different objects. The list is under no obligation to make sure iterator is consistent while iterator has to make sure it is consistent. If you call remove on the list while the iterator is ongoing, you run the risk of some strange behavior there as well but you are supposed to take care of that.
– Vinay Avasthi
Mar 22 at 3:56
That is true but List and Iterators are different objects. The list is under no obligation to make sure iterator is consistent while iterator has to make sure it is consistent. If you call remove on the list while the iterator is ongoing, you run the risk of some strange behavior there as well but you are supposed to take care of that.
– Vinay Avasthi
Mar 22 at 3:56
The CopyOnWriteArrayList will take care that the iterator is not affected by it.
– Johannes Kuhn
Mar 22 at 4:22
The CopyOnWriteArrayList will take care that the iterator is not affected by it.
– Johannes Kuhn
Mar 22 at 4:22
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292183%2fremove-operation-on-iterator-not-allowed-in-copyonwritearraylist%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292183%2fremove-operation-on-iterator-not-allowed-in-copyonwritearraylist%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
When you create a new iterator, the current copy is used. Modifying that copy will possibly change other iterators that work on the same copy.
– Johannes Kuhn
Mar 22 at 3:07
Wont the same thing happen using the list's own remove method as well?
– ghostrider
Mar 22 at 3:23
1
That is true but List and Iterators are different objects. The list is under no obligation to make sure iterator is consistent while iterator has to make sure it is consistent. If you call remove on the list while the iterator is ongoing, you run the risk of some strange behavior there as well but you are supposed to take care of that.
– Vinay Avasthi
Mar 22 at 3:56
The CopyOnWriteArrayList will take care that the iterator is not affected by it.
– Johannes Kuhn
Mar 22 at 4:22