Collection throws or doesn’t throw ConcurrentModificationException based on the contents of the Collection [duplicate]
Short answer Because the fail-fast behavior of an iterator isn’t guaranteed. Long answer You’re getting this exception because you cannot manipulate a collection while iterating over it, except through the iterator. Bad: // we’re using iterator for (Iterator<String> i = c.iterator(); i.hasNext();) { // here, the collection will check it hasn’t been modified (in effort … Read more