Java - ConcurrentModificationException: Not allow to add an entry in the collection while iterating through it

By xngo on June 23, 2019

You are getting ConcurrentModificationException because you are adding an entry in the collection while looping through the collection. It is not allowed to do that. However, Iterator.remove() is the only safe way to modify a collection during iteration. For more details, see


About the author

Xuan Ngo is the founder of He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.