Question: Ok, so I earlier posted a thread which answered alot of my questions and helped me improve my code, However, I have run into another problem, where well, I dont know why, but I think maybe the copy just points to the original object.. ( though I have tried my best to avoid this)

In my game code I have this:

```
    public void undo(){
    if (condition.size() > 0){
        board = condition.pop();
    }
}

public ArrayList<ArrayList<Cell>> copyBoard(ArrayList<ArrayList<Cell>> board){
    ArrayList<Cell> copiedArray = new ArrayList<Cell>();
    ArrayList<ArrayList<Cell>> copiedBoard = new ArrayList<ArrayList<Cell>>();

    for (ArrayList<Cell> array : board) {
        for (Cell cell : array){
            Cell copiedCell = new Cell(cell);
            copiedArray.add(copiedCell);
        }
        copiedBoard.add(array);
    }
    return copiedBoard;
}

```

and in my Cell code I have this constructor for copying the other cell:

```
    String symbol = " ";
boolean isAHole = false;

public Cell (Cell another){
    this.symbol = another.symbol;
    this.isAHole = another.isAHole;
}

```

In the program I use this to manage the stack containing the different conditions (which I want to be able to undo)

```
                if (!command.equals("undo")){
                    game.condition.push(game.copyBoard(game.board));
                }
                if (command.equals("undo")){
                    game.undo();
                }

```

But whenever I try to undo an action, one element is popped of the stack, but the condition stays just the same. (the board doesnt change) 

Do you have any ideas why?

Best regards, and thanks in advance for any help

Answer: 
You should initilize the arrayList copiedArray in each iteration, and add it and not the original one:

```
public ArrayList<ArrayList<Cell>> copyBoard(ArrayList<ArrayList<Cell>> board){

    ArrayList<ArrayList<Cell>> copiedBoard = new ArrayList<ArrayList<Cell>>();

    for (ArrayList<Cell> array : board) {
        ArrayList<Cell> copiedArray = new ArrayList<Cell>();
        for (Cell cell : array){
            Cell copiedCell = new Cell(cell);
            copiedArray.add(copiedCell);
        }
        copiedBoard.add(copiedArray);
    }
    return copiedBoard;
}

```
I think you should move copiedArray inside the first loop

```
public ArrayList<ArrayList<Cell>> copyBoard(ArrayList<ArrayList<Cell>> board){    
    ArrayList<ArrayList<Cell>> copiedBoard = new   ArrayList<ArrayList<Cell>>();

    for (ArrayList<Cell> array : board) {
        //move it here
        ArrayList<Cell> copiedArray = new ArrayList<Cell>();
        for (Cell cell : array){
            Cell copiedCell = new Cell(cell);
            copiedArray.add(copiedCell);
        }
        copiedBoard.add(copiedArray);
    }
    return copiedBoard;
}

```