/** * 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 null. */ @Override public T remove(int i) { if (i == size - 1) { size--; return null; } rangeCheck(i); T t = elementData[i]; while (i < size - 1) { elementData[i] = elementData[++i]; } // Do not throw away the removed element, put it at the end of the list instead. elementData[size - 1] = t; size--; return null; }
/** * Swap two objects of this list. * @param i index of the first object to swap * @param j index of the second object to swap * @throws IndexOutOfBoundsException if either of the indices is out of range * (<tt>i < 0 || i >= size() || j < 0 || j >= size()</tt>) */ public void swap(int i, int j) { rangeCheck(i); rangeCheck(j); unsafeSwap(i, j); }
/** * Returns the element at the specified position in this list. * * @param index index of the element to return * @return the element at the specified position in this list * @throws IndexOutOfBoundsException if the index is out of range * (<tt>index < 0 || index >= size()</tt>) */ @Override public T get(int i) { rangeCheck(i); return unsafeGet(i); }
/** * Removes the element at the specified position in this list. * This method is faster than {@link RecyclingArrayList#remove(int)} but the ith element is swapped with the last element changing the ordering of the list. * * @param index the index of the element to be removed */ public void fastRemove(int index) { if (index == size - 1) { size--; return; } rangeCheck(index); unsafeFastSwap(index, --size); }