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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2010, 03: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
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 08-02-2010, 01:59 PM
copeg's Avatar
Moderator
 
9 Highscores

Join Date: Oct 2009
Posts: 570
Thanks: 7
Thanked 131 Times in 125 Posts
copeg will become famous soon enoughcopeg will become famous soon enough

I'm feeling Sleepy
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, 05:29 PM
kite98765's Avatar
Junior Member
 

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 01:00 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:57 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.