public class SortedSet1 {
public static void main(String[] args) {
List ac= new ArrayList();
c.add(ac);
ac.add(0,"hai");
ac.add(1,"hw");
ac.add(2,"ai");
ac.add(3,"hi");
ac.add("hai");
Collections.sort(ac);
Iterator it=ac.iterator();
k=0;
while(it.hasNext()) {
System.out.println(""+ac.get(k));
k++;
}
}
}
輸出: 人工智能 海 喜 HW 海
它如何執行5次? 雖然來到海沒有下一個元素存在,所以條件錯誤。但它是如何執行的。
真正的問題是,如何使用一個Iterator,爲什麼我會收到一個indexOutOfBounds的異常。 – Cid54 2010-09-03 12:08:11