public void add ( int index , Object element ) { // reporter.updateCounter++; if ( index > elementCount ) { throw new IndexOutOfBoundsException ( "Index out of bounds: " + index + ">" + elementCount ) ; } if ( index < 0 ) { throw new IndexOutOfBoundsException ( "Index out of bounds: " + index + " < 0" ) ; } if ( elementCount >= elementData . length ) { increaseCapacity ( ) ; } for ( int i = elementCount ; i > index ; i -- ) { elementData [ i ] = elementData [ i - 1 ] ; } elementData [ index ] = element ; elementCount ++ ; }
Inserts an element at the given index