【发布时间】:2014-03-05 18:29:59
【问题描述】:
我不断收到错误消息:线程“main”java.lang.IndexOutOfBoundsException 中的异常:索引:2,大小:2。当我在将一个值推入后弹出并查看时显示为 null。当我从一个空队列中弹出/窥视时,它给了我错误。这不是将 artay 列表与队列一起使用的正确方法吗?
public T peek()
{
if(isEmpty())
throw new RuntimeException("Can't peek here");
return value.get(value.size()-1););
}
public T pop()
{
if(isEmpty())
throw new RuntimeException("Can't pop here");
T number = value.get(begin);
value.set(begin, null);
//value.remove(value.size()-1);
begin++;
return number;
}
【问题讨论】: