java - How Iterator's remove method actually remove an object -
We all know that the safest "and possibly only secure" way to remove the object from a collection, first What I want to understand, and unfortunately, a deep technical interpretation of this is not found, how it is removed if: will throw a I see in official documentation: "Erases the current element. Any attempt to call part removes the current element", I A "regular" loop = & gt; (Test equality and remove if necessary), but is iterator loop concurrently improved-why? How exactly removes the Iterator element depends on its implementation, which is different for different collections It is possible. Definitely it does not break the loop that you are inside. I have seen how the ArrayList iterator has been executed and here is the code: So it checks for concurrent amendments, removes the element by using the public EElest Delete method, and matches the pay scale of the list revisions So that concurrent improvements will not be thrown the next day. Retrieve the Iterator ; Perform a loop and remove it when necessary;
Iterator iter = Archive While (iter.hasNext ()) {object o = iter.next () if (o.equals (what i see)) {iter.remove (); }}
< Code> (object o: myCollection (). GetObjects ()) {if (o.equals (what I see)) {myCollection.remove (o); }}
concurrent correction concept , "in technical terms" "
Iterator.remove () does? Does this remove the object, break the loop and restart the loop?
InvalidState Exposure If done, then call () is not called () before calling
remove . "
Public Zero removal () {if (lastRet & Lt; 0) Throw new ones illegally (); CheckForComodification (); Try {ArrayList.this.remove (lastRet); Cursor = final reset; LastRet = -1; Expected ModeCount = modCount; } Hold (index autobuff exception ex) {new concurrent improvement concept (); }}
Comments
Post a Comment