天天看點

數組的複制。

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的起始位置。

繼續閱讀