いくつかのデータをループしてArrayList<ArrayList<Cell>>
、各ステップのを作成しています。各Cell
クラスは(とりわけ)row
とを格納します。col
私の問題は、listOfCells
後で調査すると、すべてCell
のオブジェクトが同じ行(の最後の行)を持っていることですmyData
。これは、でのみ発生し、列は本来あるrow
べき状態になります(つまり、独自の列になります)。row
適切にインクリメントしますが、そうすると、のすべての値が変更row
されますlistOfCells
。
何が原因なのかわかりません。
Cell
の作成
Cell cell = null;
int row = 0;
int col = 0;
ArrayList<Cell> tmpCellList = new ArrayList<Cell>();
ArrayList<ArrayList<Cell>> listOfCells = new ArrayList<ArrayList<Cell>>();
for (ArrayList<double> eachRow : myData) {
row++;
for (double eachCol : eachRow) {
col++;
cell = new Cell();
cell.setCol(col);
cell.setRow(row);
cell.setValue(eachCol);
tmpCellList.add(cell);
}
listOfCells.add(row-1, tmpCellList);
}
Cell
クラス
public class Cell {
private int row;
private int col;
private double value;
public void setRow(int rowIn) {
this.row = rowIn;
}
public int getRow() {
return row;
}
public void setCol(int colIn) {
this.col = colIn;
}
public int getCol() {
return col;
}
public void setValue(double val) {
this.value = val;
}
public double getValue() {
return value;
}