Trup Trup - 1 year ago 103
Java Question

Java - adding elements to list while iterating over it

I want to avoid getting

. How would I do it?

Answer Source

You may use a ListIterator which has support for a remove/add method during the iteration itself.

ListIterator<Book> iter = books.listIterator();
        iter.add(new Book(...));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download