1
我看看ArrayList的源代码,发现remove方法如下:的ArrayList remove方法
/**
* Removes the element at the specified position in this list.
* Shifts any subsequent elements to the left (subtracts one from their
* indices).
*
* @param index the index of the element to be removed
* @return the element that was removed from the list
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public E remove(int index) {
if (index >= size)
throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
modCount++;
E oldValue = (E) elementData[index];
int numMoved = size - index - 1;
if (numMoved > 0)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
elementData[--size] = null; // clear to let GC do its work
return oldValue;
}
为什么它不考虑这种情况,当指数< 0?
哇,很清楚。谢谢。 – jemy
不能upvote.vote施放的声望低于15的人是纪录,但不要改变公开显示的帖子得分 – jemy