public static < T > T [ ] replaceFirst ( T [ ] src , T oldValue , T [ ] newValues ) { int index = indexOf ( src , oldValue ) ; if ( index == - 1 ) { return src ; } T [ ] dst = ( T [ ] ) Array . newInstance ( src . getClass ( ) . getComponentType ( ) , src . length - 1 + newValues . length ) ; // copy the first part till the match System . arraycopy ( src , 0 , dst , 0 , index ) ; // copy the second part from the match System . arraycopy ( src , index + 1 , dst , index + newValues . length , src . length - index - 1 ) ; // copy the newValues into the dst System . arraycopy ( newValues , 0 , dst , index , newValues . length ) ; return dst ; }
Replaces the first occurrence of the oldValue by the newValue .