Go Back   Java Programming Forums > Java Standard Edition Programming Help > Algorithms & Recursion

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2010, 04:34 PM
Junior Member
 

Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
chrisych is on a distinguished road
Default Iterator Problem

Dear All,

I have a problem on using the iterator.

Why should I run “iter = myList.iterator();” one more time in order to get the correct results in TestLinkedList.java?

Please find the attached file for your reference.

Thank you very much!

Best Regards,
Chris.
Attached Files
File Type: zip lab.zip (414 Bytes, 2 views)



Reply With Quote Share this thread on Facebook
Sponsored Links
  #2 (permalink)  
Old 08-02-2010, 02:59 PM
Member
 

Join Date: Oct 2009
Posts: 320
Thanks: 4
Thanked 92 Times in 86 Posts
copeg will become famous soon enough

I'm feeling Mellow
Default Re: Iterator Problem

The iterator should not be re-used after a collection has been modified, in fact according to the java API if you try to use the iterator after the collection has been modified a ConcurrentModificationException may be thrown. As per the java API:
Quote:
Note that Iterator.remove is the only safe way to modify a collection during iteration; the behavior is unspecified if the underlying collection is modified in any other way while the iteration is in progress.
The Collection Interface (The Java™ Tutorials > Collections > Interfaces)
Reply With Quote
  #3 (permalink)  
Old 10-02-2010, 06:29 PM
kite98765's Avatar
Junior Member
 
1 Highscore

Join Date: Jan 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
kite98765 is on a distinguished road

I'm feeling Cheerful
Default Re: Iterator Problem

Quote:
Originally Posted by chrisych View Post
Dear All,

I have a problem on using the iterator.

Why should I run “iter = myList.iterator();” one more time in order to get the correct results in TestLinkedList.java?

Please find the attached file for your reference.

Thank you very much!

Best Regards,
Chris.
It'd be much easier if you placed your code useing the provided shortcut. If you read the "before you post" sticky thread, you would know to put your code in this:

If this is your first time here, there a few rules we would like you to follow before posting:

Quote:
1. Use code blocks for your code, please! To use code blocks, put [ code] before the code and [/ code] after it. It will look like this:


Java Code
Java Code
Some code
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterator, with ArrayList rsala004 Collections and Generics 3 25-10-2009 02:00 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java actionlistener java actionlistener jbutton addactionlistener addactionlistener java avatar hardware id convert double to integer java double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java hardware id avatar java 2 dimensional arraylist java 2d arraylist java actionlistener java addactionlistener java button actionlistener java convert double to int java convert list to map java double format java double to int java double to integer java for beginner eclippse java format double java forum java forums java get mouse position java jbutton java list to map java mouse position java programming forum java programming forums java sendkeys java.lang.reflect.invocationtargetexception java.util.arraylist jbutton actionlistener jbutton java programming forums string to int java two dimensional arraylist java writing apps for ipod touch

All times are GMT. The time now is 11:18 PM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.