public Object remove ( int index ) { if ( index >= elementCount ) { throw new IndexOutOfBoundsException ( "Index out of bounds: " + index + " >= " + elementCount ) ; } if ( index < 0 ) { throw new IndexOutOfBoundsException ( "Index out of bounds: " + index + " < 0" ) ; } Object removedObj = elementData [ index ] ; for ( int i = index ; i < elementCount - 1 ; i ++ ) { elementData [ i ] = elementData [ i + 1 ] ; } elementCount -- ; if ( elementCount == 0 ) { clear ( ) ; } else { elementData [ elementCount ] = null ; } return removedObj ; }
Removes and returns the element at given position