public static < T extends Object > T [ ] insert ( T [ ] values , T value , int index ) { @ SuppressWarnings ( "unchecked" ) T [ ] nvalues = ( T [ ] ) Array . newInstance ( values . getClass ( ) . getComponentType ( ) , values . length + 1 ) ; if ( index > 0 ) { System . arraycopy ( values , 0 , nvalues , 0 , index ) ; } nvalues [ index ] = value ; if ( index < values . length ) { System . arraycopy ( values , index , nvalues , index + 1 , values . length - index ) ; } return nvalues ; }
Creates a new array one larger than the supplied array and with the specified value inserted into the specified slot . The type of the values array will be preserved .