In the second loop, it's the same reason - you are removing an element from the list.
To remove elements from a List
while looping through it, either use standard old-fashioned for loops:
for(int i=0;i<list.size();i++) {
and remove list items inside that loop or use a ListIterator
to iterate over the list.