0
我想用ArrayList
來表示優先級隊列。所以我想在ArrayList的特定位置添加項目。但是,當我運行它,系統告訴我線程「main」中的異常java.lang.IndexOutOfBoundsException:索引:10,大小:0
異常線程 「main」 java.lang.IndexOutOfBoundsException:指數: 10,大小:0
public void enqueu(String s, int p) {
Queue.add(p,s);
}
public static void main(String[] args) {
PriorityQueue test= new PriorityQueue();
test.enqueu("x",10);
test.enqueu("Y",1);
test.enqueu("Z",3);
}
所以,你的ArrayList的大小爲0,你想在10號位置插入,你能指望什麼? –
[Exception in thread「main」java.lang.IndexOutOfBoundsException:Index:10,Size:0的可能的重複(http://stackoverflow.com/questions/39560862/exception-in-thread-main-java-郎IndexOutOfBoundsException異常折射率-10-尺寸) –