4 lines of mayhem
Throws a ConcurrentModificationException in the last line, and I have no clue why.
8 Replies
Hey, @Pleezon!
Please remember to
/close
this post once your question has been answered!
Does not throw an exception
sublist doesn't return a copy
throws an exception
sublist returns a view on the list
you cannot iterate and write on the same list at the same time
and iterating over the sublist iterates on the original list
but like
why does
List<Integer> subList = list.subList(0, 0);
still iterate
whilst list.addAll(new ArrayList<>(subList));
runsthe problem is iteratimg over the sublist
don't use the sublist after the original list changed
like.. this copies the sublist right?
this does so too
one of them works
why don't both work
:loldog: