我试图在java中使用Stack弹出二维数组。如何让堆栈弹出int [] []数据类型而不是对象?

时间:2017-04-24 17:56:30

标签: java stack

这是我的代码:我希望让getBoard()方法在弹出最新的主板后返回堆栈的主板。有什么我需要改变的吗?

    public void undo(){
        redo.push(getBoard());
        state.pop();
        board = ((int[][]) state.peek());
    }

public void redo(){
    state.push(getBoard());
    redo.pop();
    board = ((int[][])redo.peek());
}



    public void undoAction(View view){
twentyFortyEight.undo();
        customGrid.updateGrid(twentyFortyEight.getBoard());
        scoreBox.setText((Integer.toString(twentyFortyEight.getScore())));

    }

    public void redoAction(View view){
twentyFortyEight.redo();
        customGrid.updateGrid(twentyFortyEight.getBoard());
    }

1 个答案:

答案 0 :(得分:0)

要做getBoard()方法,你需要创建这个方法,然后在那里做一些事情或从已经存在的其他方法调用

int[][] board;
    public int[][] getBoard(){
int[][] b;
//...
return b;
    }

board = getBoard();