You are not permitted to mutate a list while you are iterating over it. Your l.remove(j)
causes the list l
to change, but you’re inside a for (Integer j : l)
loop.
2
solved java+ ConcurrentModificationException forEach(enhanced) loop single thread [duplicate]