when i modify(i.e., add or remove an object) from a collection while iterating it using for-each loop its giving ConcurrentModificationException.
how can i avoid it? please suggest
You can avoid ConcurrentModificationException by using the Iterator.
If you want to be able to both add and remove elements while traversing a collection, use a