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…
public class ArrayCopy{ public static void main(String []args){ int []a = {1,3,4,5}; toPrint(a); int []aFor=new int[a.length]; //1.for循环复制 System.out.println("===========1.使用for复制"); for(int i=0;i<a.length;i++){ aFor[i]=a[i]; } aFor[2]=10;//改…