• Post Reply Bookmark Topic Watch Topic
  • New Topic

ConcurrentModificationException  RSS feed

 
Deepa Rajesh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to iterate through ArrayList of LinkedHashMap and remove the specific data from each map. Finally, i got ConcurrentModificationException.I tried Iterator too. It didn't work.Please give me suggestions.It is SingleThread Environment/Java7.

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't new to Java 7, but would have already caused the same exception years ago.

The problem is with the way you're iterating and removing. If you iterate using an Iterator (which a for-each loop uses in the background), then you cannot change the collection you're iterating over except through the Iterator*.

So change your inner loop to do just that. It means you need an explicit Iterator:

* Some later collection types like ConcurrentHashMap are more lenient.
 
Deepa Rajesh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!