【发布时间】:2021-03-03 00:14:30
【问题描述】:
我有以下代码,其中每当我将一个新的二维数组传递给列表时,列表中现有的二维数组都会自动更新为刚刚传递给构造函数的二维数组。
private List <Timetable> timetablelist;
public TimetableManager() {
this.timetablelist = new ArrayList<Timetable>();
}
String[][] data = new String[6][10];
String tchridcls;
try{
BufferedReader br = new BufferedReader(new FileReader(file));
Object[] lines = br.lines().toArray();
int i=0,j=0;
while(i<lines.length){
String[] row = lines[i].toString().split(",",-1);
tchridcls=row[0];
data[j][0]=row[1];
data[j][1]=row[2];
data[j][2]=row[3];
data[j][3]=row[4];
data[j][4]=row[5];
data[j][5]=row[6];
data[j][6]=row[7];
data[j][7]=row[8];
data[j][8]=row[9];
data[j][9]=row[10];
i++;
j++;
if(i%6==0){
Timetable t = new Timetable(data,tchridcls);
timetablelist.add(t);
j=0;
}}}
这是课表课
public class Timetable {
private String[][] timetable = new String[6][10];
private String teacherid_class;
public Timetable(String[][] timetable, String teacherid_class){
this.teacherid_class = teacherid_class;
this.timetable = timetable;
}
public String getteacherid_class(){
return teacherid_class;
}
public String[][] gettimetable(){
return timetable;}
我已经检查过将data[][] 传递给构造函数后出现的问题。由于某种原因,它使用新提供的 data[][] 2d 数组更新列表中所有现有对象的 data[][] 2d 数组。
这个问题花了很多时间请帮助我!!
【问题讨论】: