System.arraycopy方法解释
数组拷贝
public static native void arraycopy(Object src, int srcPos,
Object dest, int destPos,
int length);
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); } } }
原文地址:https://segmentfault.com/a/1190000017271507?utm_source=tag-newest