public static void main(String[] args) {
List<List<Integer>> list = new ArrayList<List<Integer>>(); // final list
List<Integer> l = new ArrayList<Integer>(); // l is list
List<Integer> m = new ArrayList<Integer>(); // m is list
List<Integer> temp = new ArrayList<Integer>();
l.add(1);
l.add(2);
l.add(3); // list l
m.add(4);
m.add(5);
m.add(6); // list m
temp.addAll(l); // add l to temp
list.add(temp);
System.out.println("temp: "+temp);
System.out.println("list: "+list);
temp.addAll(m); // add m to temp1
list.add(temp);
System.out.println("temp: "+temp);
System.out.println("list: "+list);
}
結果是列表,任何人都可以回答
temp: [1, 2, 3]
list: [[1, 2, 3]]
temp: [1, 2, 3, 4, 5, 6]
list: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]]
我覺得應該是:
temp: [1, 2, 3]
list: [[1, 2, 3]]
temp: [1, 2, 3, 4, 5, 6]
list: [[1, 2, 3], [1, 2, 3, 4, 5, 6]]
爲什麼上次名單[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]]
?
哪裏定義了temp1? –