• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ConcurrentModificationException

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it.Thank you.
reply
    Bookmark Topic Watch Topic
  • New Topic