【发布时间】:2016-09-18 16:15:42
【问题描述】:
我想使用ArrayList 来表示优先级队列。所以我想在 ArrayList 的特定位置添加项目。但是当我运行它时,系统告诉我
线程“主”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 位插入,你期望什么?
标签: java