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 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 (); }}   

What I want to understand, and unfortunately, a deep technical interpretation of this is not found, how it is removed if:

 < Code> (object o: myCollection (). GetObjects ()) {if (o.equals (what I see)) {myCollection.remove (o); }}   

will throw a concurrent correction concept , "in technical terms" " Iterator.remove () does? Does this remove the object, break the loop and restart the loop?

I see in official documentation:

"Erases the current element. Any attempt to call InvalidState Exposure If done, then call () is not called () before calling remove . "

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:

  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 (); }}   

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.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -