如何将java类新建为int []类型

时间:2015-06-05 16:27:23

标签: java

如何将int[]转换为课程Cell

public List<int[]> getThem(List<int[]> theList) {
    List<int[]> list1 = new ArrayList<int[]>();
    for (int[] x : theList)
        if (x[0] == 4)
            list1.add(x);
    return list1;
}

我想重构如下:

public List<Cell> getFlaggedCells() {
    List<Cell> flaggedCells = new ArrayList<Cell>();
    for (Cell cell : gameBoard)
        if (cell.isFlagged())
            flaggedCells.add(cell);
    return flaggedCells;
}

如何将课程Cell设为int[]

1 个答案:

答案 0 :(得分:1)

您需要在单独的java文件中创建一个名为Cell的类。该类包含int []的位置。我看到你在Cell类上也有一个isFlagged()方法,所以我也把它放在那里。

public class Cell {
    public int[] values;
    private boolean flag;

    public boolean isFlagged() {
        return flag;
    }

    public setFlag(boolean flag) {
        this.flag = flag;
    }
}