Hi all,
I have created some of the examples of the JCF (
Java Collections Framework).One thing that had confused me is that
When we are iterating a Colection say ArrayList using the iterator and during the iteration if we try to modify the collection by by calling the ArrayList's add method then it will give me the exception
ConcurrentModificationException.
But i did the iterations and try to add the new element by using the listiterator's add method then it is not giving me such exception.
My Question is why is such a different behaviour is there? Why java allowed to modify the collection using the iterator's own methods when iterating and why not through the arraylist method ?
After all both ways we are going to add the element to the ArrayList .
Please any help would be appreciated.