美文网首页
System.arraycopy()方法介绍及使用

System.arraycopy()方法介绍及使用

作者: winlee | 来源:发表于2020-03-18 09:59 被阅读0次
    /*
     * @param      src      the source array.
     * @param      srcPos   starting position in the source array.
     * @param      dest     the destination array.
     * @param      destPos  starting position in the destination data.
     * @param      length   the number of array elements to be copied.
     * @exception  IndexOutOfBoundsException  if copying would cause
     *               access of data outside array bounds.
     * @exception  ArrayStoreException  if an element in the <code>src</code>
     *               array could not be stored into the <code>dest</code> array
     *               because of a type mismatch.
     * @exception  NullPointerException if either <code>src</code> or
     *               <code>dest</code> is <code>null</code>.
     */
    @FastNative
    public static native void arraycopy(Object src,  int  srcPos,
                                        Object dest, int destPos,
                                        int length);

作用:将指定源数组中的数组从指定位置复制到目标数组的指定位置。

参数:

src - 源数组。

srcPos - 源数组中的起始位置。

dest - 目标数组。

destPos - 目的地数据中的起始位置。

length - 要复制的源数组元素的数量。

举例:

//原数组:
int[] arr={1,2,3,4,5,6,7,8,9,0};
//目标数组:
int[] Arr=new int[4];
//操作:源数组从第1位开始copy,目标数组从第0位开始append,共copy四个元素    
System.arrayCopy(arr,1,Arr,0,4);

相关文章

网友评论

      本文标题:System.arraycopy()方法介绍及使用

      本文链接:https://www.haomeiwen.com/subject/ckxqyhtx.html