Friday, April 24, 2009


If you try to modify a list while iterating through it, then you will encounter the ConcurrentModificationException.

The foreach loop is *is* syntactic sugar for iterating. However, you need to call remove on the iterator - which foreach doesn't give you access to.

for (SgeApAdapter apAdapter : apsToUpdate) {
if (...) {

It throws ConcurrentModificationException. We have to use iterator explcitly to remove item in collection.

No comments: