2 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊
問(wèn)題是對(duì)于您配對(duì)相同列表對(duì)象的每個(gè)鍵,在 for 循環(huán)中使用new ArrayList(Collection<? extends E> c)構(gòu)造函數(shù)每次創(chuàng)建新對(duì)象
if (records.size() > 0) {
for (Integer record: records) {
dateMap.get(Integer.parseInt(record)); //you can remove this line
dateMap.put(record,new ArrayList(resultDate));
}
}
公共 ArrayList(集合 c)
按照集合的迭代器返回的順序構(gòu)造一個(gè)包含指定集合元素的列表。

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊
您的值可能使用一個(gè)帶有 diff 別名的列表
List one = new AraayList();
map.put("k1", one);
map.put("k2", one);
List alias = one;
map.put("k3", alias);
這些值使用相同的實(shí)例,當(dāng)您更新一個(gè)時(shí),其他的會(huì)看到更改。
添加回答
舉報(bào)