/** * Remove a value from an array */ private V removeFromArray( V value ) { checkAndDeserialize(); // First check that the value is not already present in the ValueHolder int pos = findPos( value ); if ( pos < 0 ) { // The value does not exists : nothing to do return null; } // Ok, we just have to delete the new element at the right position // First, copy the array V[] newValueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), valueArray.length - 1 ); System.arraycopy( valueArray, 0, newValueArray, 0, pos ); System.arraycopy( valueArray, pos + 1, newValueArray, pos, valueArray.length - pos - 1 ); // Get the removed element V removedValue = valueArray[pos]; // And switch the arrays valueArray = newValueArray; return removedValue; }