public V remove ( Object key ) { // Check if the key is in the map Integer index = keyToIndex . get ( key ) ; if ( index == null ) { return null ; } // Leave the data in the array but remove its key keyToIndex . remove ( key ) ; keySet . remove ( key ) ; // Remove the data from the array V removedValue = data . remove ( index . intValue ( ) ) ; // Go through the whole key to index map reducing by one the value of any indexes greater that the removed index for ( K nextKey : keyToIndex . keySet ( ) ) { Integer nextIndex = keyToIndex . get ( nextKey ) ; if ( nextIndex > index ) { keyToIndex . put ( nextKey , nextIndex - 1 ) ; } } // Return the removed object return removedValue ; }
Removes the mapping for the specified key from this map if present .