我不确定为什么哈希图在这个while循环内和while循环之外打印出不同的东西。我在while循环之外声明了地图,所以我认为它的内部和外部应该是相同的。在代码中,我在 while 循环内部和外部都有相同的打印语句,但它们打印的内容不同。地图的键是 personCounter,它是递增的并且应该是唯一的。非常感谢您的帮助。
public Map<Integer, double[]> setRating(CSVReader r, int taskNum, int taskWeightNumHeader)
throws NumberFormatException, IOException {
String[] line;
int personCounter = 0;
Map<Integer, double[]> indivTaskRating = new HashMap<Integer, double[]>();
while ((line = r.readNext()) != null) {
double[] perTaskWeight = new double[5];
personCounter++;
int multiplier = taskNum * 5;
perTaskWeight[2] = Double.parseDouble(line[taskWeightNumHeader + multiplier]);
perTaskWeight[1] = Double.parseDouble(line[taskWeightNumHeader + multiplier + 1]);
perTaskWeight[0] = Double.parseDouble(line[taskWeightNumHeader + multiplier + 2]);
perTaskWeight[3] = Double.parseDouble(line[taskWeightNumHeader + multiplier + 3]);
perTaskWeight[4] = Double.parseDouble(line[taskWeightNumHeader + multiplier + 4]);
indivTaskRating.put(personCounter, perTaskWeight);
for (int j = 0; j < 5; j ++) {
System.out.println("personID: " +1+ ", rating: " +indivTaskRating.get(1)[j]);
}
}
for (int j = 0; j < 5; j ++) {
System.out.println("personID: " + 1+ ", rating: " +indivTaskRating.get(1)[j]);
}
return indivTaskRating;
}