天天看点

数组的复制。

arraycopy System 类中的 arraycopy 方法的使用。

语法:

       System.arraycopy(from, fromIndex, to, toindex, count);

       public class java {

       public static void main(String[] args) {

               int[] small = {2,3,5,7,11,13};

               int[] big   = {1001,1002,1003,1004,1005,1006,1007};

               System.arraycopy(small,2,big,3,4);

               for (int a=0; a<big.length; a++)

               {

                           System.out.println(a+" entry after copy  "+big[a]);

                           }

       }

       }

运行结果:

      0 entry after copy 1001

      1 entry after copy 1002

      2 entry after copy 1003

      3 entry after copy 5

      4 entry after copy 7

      5 entry after copy 11

      6 entry after copy 13

总结:

         刚刚开始接触JAVA,对于语法不是很了解。一时很容易忘记了,所以写下来,便于以后参考。

         System.arraycopy(from, fromIndex, to, toindex, count);

         from:是源数组。

         fromindex:是要复制的数组成员的起始index,本列中就是5。和count 可以确定要复制的数组成员的个数。本例中就是5,7,11,13。

         to:是目标数组。

         toindex:是数组成员复制到目标数组的index的起始位置。

继续阅读