E (int index) { int size = mySize; checkOutOfBounds(index, size); E oldValue; switch (size) { case 0: // impossible case 1: oldValue = asElement(); myElem = null; break; case 2: { Object[] array = asArray(); oldValue = getFromArray(array, index); myElem = array[1 - index]; break; } default: Object[] array = asArray(); oldValue = getFromArray(array, index); int numMoved = size - index - 1; if (numMoved > 0) { System.arraycopy(array, index + 1, array, index, numMoved); } array[size - 1] = null; } mySize--; modCount++; return oldValue; }