我有存儲組合框,當我寫獲取其項目的代碼,也物品的數量可以changed.but:爲什麼這個關於combobox的代碼不起作用?
List<String> bIHELessons = new ArrayList<String>();
for (int i=0;i<jComboBox1.getItemCount();i++) {
String lessons = (String) jComboBox1.getItemAt(i);
if (lessons != null&& lessons.trim().length()!=0) {
bIHELessons.add(lessons);
System.out.println(bIHELessons.toString());
}
}
「的電腦,代碼:21」,「31史,代號」
它會顯示在控制檯這些句子:
[電腦,代碼= 21]
[電腦,代碼= 21,歷史,郵編:31]
你的問題到底是什麼?你的程序做了什麼? 我不編程JAVA,但我覺得很奇怪你實例化一個arraylist並將其分配給一個字符串列表。 您的biHELessons.toString()會轉儲您在循環中添加的項目的內容,所以我不認爲您的結果很奇怪。 – 2009-11-25 13:51:07
你期望程序做什麼? @Michel'ArrayList'實現'List'接口。 – Amarghosh 2009-11-25 13:53:44
請編輯您的文章並說出您期望得到的內容。現在看起來沒問題... – 2009-11-25 13:54:52