So, I have tried to create a loop in Java that I want to copy my list of lists of cells, however I get the error java.util.ConcurrentModificationException
the second time the inner loop is run. Any ideas why?
Here is the code:
private ArrayList<ArrayList<Cell>> copyBoard(ArrayList<ArrayList<Cell>> board) {
ArrayList<ArrayList<Cell>> copiedBoard = null;
for (ArrayList<Cell> array : board) {
int i = 0;
for (Cell cell : board.get(i)) {
Cell copiedCell = new Cell();
copiedCell = cell;
array.add(copiedCell);
i++;
}
copiedBoard.add(array);
}
return copiedBoard;
}