나는 각 단계의 ArrayList<ArrayList<Cell>>
을 생성하면서 일부 데이터를 반복합니다. 각 Cell
클래스는 row
과 col
을 저장합니다. 그들은 (그 자체로 고유 한)해야으로개인 변수가 클래스 외부에서 수정 됨 - Java
내 문제는 내가 내 listOfCells
이후에 조사 할 때, 모든 Cell
객체가 같은 행 (myData
의 마지막 행을 가지고 있다는 것입니다.이 내용은 row
으로 발생, 열은 . 내가 말할 수있는 건, row
가 제대로 증가되지만 그렇게되면, 내가이 원인을 무엇 아무 생각이 내 listOfCells
.
에 row
의 모든 값을 변경합니다.
Cell
의
만들기당신의 행 16,
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;
}
첫 번째 for 루프 안에'ArrayList tmpCellList = new ArrayList ();을 이동하십시오. –
| |