File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to delete the map elements when iterating the map
 
Similar Threads
Map
newbie simple java program
Why Iterator doesn't iterators according to elements priority ?
Using a sorted map...
LinkHashMap problem!