List<List<Integer>> result = new ArrayList<List<Integer>>();
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(5);temp.add(6);
result.add(temp);
temp.clear();
我編寫了類似上面的代碼,當我調試代碼時,我發現結果包含1的大小,但值(5,6,...)我在應用清除功能後會丟失,任何人都可以解釋爲什麼?Java ArrayList.clear()函數
您沒有清除結果列表,所以它仍然有一個元素(一個空列表)。 – Keppil
@StefanoSanfilippo它似乎只是想刪除2D列表中的一個項目? –
對不起,我的意圖是清除溫度不是結果列表。我的意思是在清除臨時成員之後,即使結果的列表也受到影響 – i3wangyi