public class Test { public static void main(String[] args) { Integer[] a = {1,2,3}; Integer[] b = {4,5,6}; Integer[] c = new Integer[a.length+b.length]; System.arraycopy(a, 0, c, 0, a.length); System.arraycopy(b, 0, c, b.length, b.length); for(Intege…
public class ArraycopyTest { public static void main(String[] args) { //静态初始化两个长度不同的数组 int src[] = {1,2,3,4,5,6}; int dest[] = {10,9,8,7,6,5,4,3,2,1}; //将数组src的4个元素copy到数组dest中 System.arraycopy(…
package study.stage2; import java.util.Arrays; /** * Created by Sandy.Liu on 2017/7/19. */public class ArrayTest { public static void main(String[] args) throws Exception{ int array[] = {3,4,2,24,6,-23,-4,-56}; System.out.println(array.length);//8 pr…
当我还年幼的时候,我很任性,复制数组也是,写一个for循环,来回倒腾,后来长大了,就发现了System.arraycopy的好处. 为了测试俩者的区别我写了一个简单赋值int[100000]的程序来对比,并且中间使用了nanoTime来计算时间差: 程序如下: int[] a = new int[100000]; for(int i=0;i<a.length;i++){ a[i] = i; } int[] b = new int[100000]; int[] c = new int[100000…
1.Object.clone() 简单直接,只能对源数组完整地复制 2.Arrays.copyOf(T[] original, int newLength) 可以只复制源数组中部分元素,但复制的起始位置固定为0 3.Arrays.copyOfRange(T[] original, int from, int to) 可以指定复制的起始位置 4.System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length…