System.arraycopy的底层逻辑

 这个System.arraycopy其实底层逻辑本质和Arrays.copyOf是一样的

分析源码可以得出Arrays.copyOf也会走到System.arraycopy这个方法

下面是对参数的具体解读

/**
 * @author 徐云鹏
 * 仅供学习交流!
 */
public class System_ {
    public static void main(String[] args) {
        int arr1[] = {1, 6, 8};
        int arr2[] = new int[3];
        System.arraycopy(arr1, 0, arr2, 0, 3);
        /**
         * 解读--
         *      * @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.
         *      这五个参数是源码中给到的,通过分析可得出
         *      第一个src即为需要传递的数组,就是要复制的数组
         *      第二个secPos代表从src的哪一个(下标)元素开始传递
         *      dest代表要被传递(复制到的数组)到的数组
         *      destPos代表从dest哪一个(下标)元素开始接收
         *      length代表从源数组拷贝多少个数据到新数组  src --> dest*/
    }
}

注意--

数组的拷贝长度是有范围的 如果超出了,会报数组越界异常ArrayIndexOutOfBoundsException

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值