数组的拷贝

本文详细介绍了Java中Arrays类提供的三种关键方法:copyOfRange()用于复制数组片段,copyOf()创建指定长度的新数组,arrayCopy()用于元素级的数组拷贝。通过实例演示,帮助理解这些在数组操作中的核心技巧。

一般采用三种方法:

1.Arrays.copyOfRange(T[] original, int from, int to)

@param original the array from which a range is to be copied
 @param from the initial index of the range to be copied, inclusive
 @param to the final index of the range to be copied, exclusive.

2.Arrays.copyOf(T[] original, int newLength)

* @param original the array to be copied
     * @param newLength the length of the copy to be returned
     * @return a copy of the original array, truncated or padded with zeros
     *     to obtain the specified length

3.System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)

@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.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值