public V remove ( int index ) throws IndexOutOfBoundsException { // Check that the index is not too large if ( index >= data . size ( ) ) { throw new IndexOutOfBoundsException ( ) ; } // Get the key for the index by scanning through the key to index mapping for ( K nextKey : keyToIndex . keySet ( ) ) { int nextIndex = keyToIndex . get ( nextKey ) ; // Found the key for the index, now remove it if ( index == nextIndex ) { return remove ( nextKey ) ; } } // No matching index was found throw new IndexOutOfBoundsException ( ) ; }
Removes the specified index from the data structure . This only works if the index already exists .