List list = new List(Types::String);
ListIterator iterator;
;
list.addEnd("a");
list.addEnd("b");
list.addEnd("c");
list.addEnd("d");
iterator = new ListIterator(list);
while (iterator.more())
{
if (iterator.value() == "b")
list.addEnd("e");
iterator.next();
}
info(list.toString());
There is instance of List class retaining arbitrary string values. ListIterator class is instantiated for traversing through elements in the list. What will happen when we try to add a new element in the list inside iteration block? New element will be added to collection! In Java for iterators implemented other behavior. If an iterator is obtained, modifying the underlying collection will throw a ConcurrentModificationException. Pay attantion to this difference.