的ArrayList你好,我要填寫我的ArrayList ArrayList的命名爲QuestionIdList_Section
爲此,我必須做出一個名爲QUESTION_ID_Of_SectionId_Temp
臨時ArrayList中添加到QuestionIdList_Section
設置數值爲ArrayList的
我的代碼後,將明確是如下這樣您就可以瞭解我已經codded:
public static ArrayList<String> QUESTION_ID_Of_SectionId_Temp = new ArrayList<String>();
public static ArrayList<ArrayList<String>> QuestionIdList_Section = new ArrayList<ArrayList<String>>();
QUESTION_ID_Of_SectionId_Temp.add("Hello");
QUESTION_ID_Of_SectionId_Temp.add("Hiii");
QuestionIdList_Section.add(0,QUESTION_ID_Of_SectionId_Temp);
Log.i(TAG, "******Before " + QuestionIdList_Section);
Log.i(TAG, "******Before "+ QUESTION_ID_Of_SectionId_Temp);
QUESTION_ID_Of_SectionId_Temp.clear();
Log.i(TAG, "******After " + QuestionIdList_Section);
Log.i(TAG, "******After " + QUESTION_ID_Of_SectionId_Temp);
執行的代碼後,我得到不同的結果兩個變量。
如下:
******Before [[Hello, Hiiii]]
******Before [Hello, Hiiii]
******After [[]]
******After []
可以有一個人請幫助我明白我缺乏在這些地方我。我想清除溫度arraylist,這樣我可以把UESTION_ID_Of_SectionId_Temp
不同的值,因此對於第二個索引QuestionIdList_Section
我將設置值不同。
在此先感謝。
您是否清除了QuestionIdList_Section? –
使用'QUESTION_ID_Of_SectionId_Temp.remove(item)'而不是'QUESTION_ID_Of_SectionId_Temp.clear();' – Deepzz
只是改變'QuestionIdList_Section.add(0,QUESTION_ID_Of_SectionId_Temp);'到'QuestionIdList_Section。添加(0,新的ArrayList(QUESTION_ID_Of_SectionId_Temp));'和你的代碼將工作,因爲你需要複製ArrayList而不是傳遞引用之前清理它 –