This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes problem in remove() in iterator. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in remove() in iterator." Watch "problem in remove() in iterator." New topic
Author

problem in remove() in iterator.

Ritesh raushan
Ranch Hand

Joined: Aug 29, 2012
Posts: 100
problem in remove() when i remove this method then output is infinite loop,
but when i write this method the output is 13,14,15,13,13.i don't know how came


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

If you read the docs, you'll see that calling next() and previous() doesn't just return the next or previous element. It also changes the state of the iterator, moving it one forward or one back. If you don't call remove(), then you're just going forward, back, forward, back, ... forever, and never getting to the end of the list.
Paul Witten
Ranch Hand

Joined: Oct 10, 2012
Posts: 86
Jeff Verdegan wrote:If you don't call remove(), then you're just going forward, back, forward, back, ... forever, and never getting to the end of the list.

Did not know that.

Reminds me of Vote=Left, Vote=Right, Vote=Left, Vote=Right ...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in remove() in iterator.