When more than one iterator accessing the same collection reference , then this concurrent modification exception will occur.
Ex:-
List list = new LinkedList();
Iterator it1 = list.iterator();
Iterator it2 = list.iterator();
it1.next();
it1.remove();
it2.next();
The above code will surely end up in concurrent modification exception.
Say now, if this is the case , how to tackle this exception.
You can have any number of iterators , make all your iterators readable , make only one read and write.
Tags:-
Ex:-
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ70x4nZViCL8JrdGMfs70U3emeZjLXc8Y2Vkt4uJhltW9_9bYnSX9-Bhl50So8jDtI3uehEaRfw-n6exYRyQT7tAxIIWd7HpLutgSxZ1cpeLSoZOo7q8ZSG5cVWgxvUmttzbdPNbSlJA/s1600/ConcurrentModificationException.jpg)
Iterator it1 = list.iterator();
Iterator it2 = list.iterator();
it1.next();
it1.remove();
it2.next();
The above code will surely end up in concurrent modification exception.
Say now, if this is the case , how to tackle this exception.
You can have any number of iterators , make all your iterators readable , make only one read and write.
Tags:-