SSISO Community

시소당

[sample] System.arraycopy() 부분복사

public  class  ArrayCopyMain  {
    public  static  void  main(  String[]  args  )  {
        int[]  source  =  new  int[]  {  5,  4,  6,  9,  7,  9  };
        int[]  target  =  {  100,  200,  300,  400,  500,  600,  700  };

        //  source의  2번째  첨자부터  4개를  target의  3번째  첨자부터  복사
        System.arraycopy(  source,  2,  target,  3,  4  );
        for  (  int  i  =  0;  i  <  target.length;  i++  )  {
            System.out.println(  "target["  +  i  +  "]:  "  +  target[i]  );
        }
    }
}


//  output
target[0]:  100
target[1]:  200
target[2]:  300
target[3]:  6
target[4]:  9
target[5]:  7
target[6]:  9

하나의  객체만을  가지고  저렇게  쉽게  복사할  수  있다.  (로직한줄도  간과하면  안되요..)

출처  :  http://neouser.tistory.com/32

1085 view

4.0 stars