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 how to delete the map elements when iterating the map 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 "how to delete the map elements when iterating the map" Watch "how to delete the map elements when iterating the map" New topic
Author

how to delete the map elements when iterating the map

jing hu
Ranch Hand

Joined: Jun 30, 2009
Posts: 63
I want to delete some elements when iterating the map.

Like this.


but it will fail and throw java.util.ConcurrentModificationException. So How can I modify the map when iterating it.
I want to know a convenient method which do not need many codes.
Thanks
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
replace line 19 with:


http://javasign.blogspot.com/
jing hu
Ranch Hand

Joined: Jun 30, 2009
Posts: 63
Thanks, I get it.
 
Don't get me started about those stupid light bulbs.
 
subject: how to delete the map elements when iterating the map