php arraycopy,System.arraycopy方法解释

**/*

* @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 src

* array could not be stored into the dest array

* because of a type mismatch.

* @exception NullPointerException if either src or

* dest is null.

*/

public static native void arraycopy(Object src, int srcPos,Object dest, int destPos,int length);**

例子如下:

package test.demo;

public class ArrayCopyTest {

public static void main(String[] args) {

char[] src = new String("hellow").toCharArray();

char[] dest = new String("12345789").toCharArray();

System.out.print("src源数组为:");

for(char c : src){

System.out.print(c);

}

System.out.print("\ndest目标数组为:");

for(char c : dest){

System.out.print(c);

}

/*

* 开始执行数组复制操作

* 将源数组['h','e','l','l','o','w']从数组下标0开始的4位长度的数组['h','e','l','l']

* 复制到目标数组['1','2','3','4','5','6','7','8'],从下标为3的位置开始

*/

System.arraycopy(src,0,dest,3,4);

System.out.print("\n复制完成之后的目标数组为:");

for(char c : dest){

System.out.print(c);

}

}

}

结果输出如下:

src源数组为:hellow

dest目标数组为:12345789

复制完成之后的dest目标数组为:123hell9

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值