This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes avoiding ConcurrentModifciation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "avoiding ConcurrentModifciation" Watch "avoiding ConcurrentModifciation" New topic
Author

avoiding ConcurrentModifciation

Carl Jenkins
Ranch Hand

Joined: Feb 19, 2006
Posts: 39
Hello all -

I am iterating (or tying to) over a list and needed to remove one or more items from this list. I keep running into the ConcurrentModification exception.

I have read that java 5 has the CopyOnWrite to help with this but I need something in java 1.4...

So far I have been unsuccessfully in figuring out how to get around this issue with out actually catching the exception and re-calling the method which I am not sure would work yet but would rather not do.

Any help would be great!
Carl Jenkins
Ranch Hand

Joined: Feb 19, 2006
Posts: 39
I found the answer <embarrassed> with a quick search on this forum</embarrassed>

What I need to do is call remove()from the iterator not the list!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Why be embarrassed? You managed to get the answer and tell others what it was. More something to be pleased about.
 
Don't get me started about those stupid light bulbs.
 
subject: avoiding ConcurrentModifciation