In the documentation for Iterator#remove
throws
IllegalStateException
- if the next method has not yet been called, or the remove method has already been called after the last call to the next method.
So it looks like x.remove()
is being called twice before next()
is being called.
Just make sure to break
out of the inner loop after calling x.remove()
.