Add elements to a List while iterating over it. (Java) [duplicate]
You can’t modify a Collection while iterating over it using an Iterator, except for Iterator.remove(). However, if you use the listIterator() method, which returns a ListIterator, and iterate over that you have more options to modify. From the javadoc for add(): The new element is inserted before the implicit cursor: … a subsequent call to … Read more