Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to delete the map elements when iterating the map

 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
replace line 19 with:
 
jing hu
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I get it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic