When I try to do
ListIterator<Integer> iter = list.listIterator(list.size());
for (int i = 0; i < size; i++) {
iter.hasPrevious();
list.addFirst(iter.previous());
}
I get ConcurrentModificationException. I know what that means, but how can I add first element to a List and iterate it at the same time? Execution time and memory limit are crucial.