HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
ArrayList<Integer> al = new ArrayList<Integer>();//arraylist as value
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 5; i++) {
al.add(i + j);
}
System.out.println(al);
System.out.println(j);//key value
map.put(j, al);
System.out.println(map);
al.clear();
}
为什么最后一个值数组列表会在所有键上被覆盖?如何避免过度书写?