• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arraylist - ConcurrentModificationException  RSS feed

 
Jake Obrien
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys, Kind of hit a wall with this one...
I understand the concept of why I'm getting the concurrent error with an Arraylist, however it doesn't always seem to throw the error.
Of the 2 code snippets below, only the second one throws the error. The 1st one compiles and run without any issue.
From everything I've been reading it should not allow for the removal of an item from an Arraylist inside a for each loop???

1.



2.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned in the JavaDoc, the fail-fast mechanism is best effort. This means that you can't depend on it to fail correctly... and of course, you can't depend on it to work correctly (or consistently) with all versions of the JVM, when used incorrectly, either.

Henry
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!