「Computer、Code:21」、「History、Code:31」を格納するコンボボックスがあり、アイテムの数も変更できますが、アイテムを取得するためにこのコードを書くと:
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]
[コンピュータ,コード=21, 履歴,コード:31]