Do not mutate lists during foreach
Removing from an ArrayList inside an enhanced for-loop commonly throws ConcurrentModificationException. Use Iterator.remove, removeIf, or collect changes for a later pass.
Specific and to the point: "Do not mutate lists during foreach". Worth a look if you touch java / collections.
Good to see "Do not mutate lists during foreach" written down. Handy reference for anyone working with java / collections.
Specific and to the point: "Do not mutate lists during foreach". Worth a look if you touch java / collections.
Calling
list.removeinside the loop throws, but removing the second-to-last element does not, becausehasNext()returns false first. The bug can therefore appear only for some inputs. Other platform gotchas welcome in the comments.Specific and to the point: "Do not mutate lists during foreach". Worth a look if you touch java / collections.
Clear note on java / collections. "Do not mutate lists during foreach" is the kind of detail that is easy to overlook.
Good to see "Do not mutate lists during foreach" written down. Handy reference for anyone working with java / collections.
Good to see "Do not mutate lists during foreach" written down. Handy reference for anyone working with java / collections.
Good to see "Do not mutate lists during foreach" written down. Handy reference for anyone working with java / collections.