public static int[] insert(int[] array, int currentSize, int index, int element) {
        assert currentSize <= array.length;

        if (currentSize + 1 <= array.length) {
            System.arraycopy(array, index, array, index + 1, currentSize - index);
            array[index] = element;
            return array;
        }

        int[] newArray = new int[growSize(currentSize)];
        System.arraycopy(array, 0, newArray, 0, index);
        newArray[index] = element;
        System.arraycopy(array, index, newArray, index + 1, array.length - index);
        return newArray;
    }
public static int [ ] insert ( int [ ] array , int currentSize , int index , int element ) { assert currentSize <= array . length ; if ( currentSize + 1 <= array . length ) { System . arraycopy ( array , index , array , index + 1 , currentSize - index ) ; array [ index ] = element ; return array ; } int [ ] newArray = new int [ growSize ( currentSize ) ] ; System . arraycopy ( array , 0 , newArray , 0 , index ) ; newArray [ index ] = element ; System . arraycopy ( array , index , newArray , index + 1 , array . length - index ) ; return newArray ; }
Primitive int version of {@link #insert(Object[], int, int, Object)}.