Problem with adding objects to ArrayList

A container being iterated by an “enhanced” for ( : ) loop can’t change it’s size(). :no_entry:

Use a vanilla for ( ; ; ) loop instead: :bulb:

for (int len = cell.size(), i = 0; i < len; ++i)
  if (cell.get(i).overlap())  cell.add(new Cell());
2 Likes