Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

age old question

Thread view: 
newsnet customer - 22 Jan 2006 09:44 GMT
Hi

I have an arraylist and associated with it 2 iterators. When iterating through the arraylist in the forward and reverse direction and removing nodes under certain criteria. I get a concurrent modification error. This is with using the iterators remove() method and not the arraylist remove method. The only workaround for this is to "mark" the nodes and then remove them after the iteration. Is there a way to do this during the iteration process?

Cheers,
Sharp Tool
NullBock - 22 Jan 2006 12:47 GMT
The problem is the *two* iterators.  You may not use an iterator *and*
modify a list in any other way--in your case, with a second iterator.
You shouldn't have any problems at all iterating through a list and
altering it, so long as you are using only one iterator at a time.

Walter Gildersleeve
Freiburg, Germany

______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
Adam Maass - 23 Jan 2006 00:40 GMT
>Hi
>
[quoted text clipped - 6 lines]
>workaround for this is to "mark" the nodes and then remove them after the
>iteration. Is there a way to do this during the iteration process?

As has been pointed out, ConcurrentModificationException will arise if the
backing ArrayList of one iterator is modified in any way outside of the
"remove" method of that iterator -- including the "remove" method of a
second iterator on the same ArrayList. This is expected and is as
documented.

It might be possible to build up a second list of elements to keep while
iterating through your first ArrayList, then replace the original.

-- Adam Maass


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.