Java 배열 클론

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:50 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Java clone array
자바 배열 클론
import java.util.Arrays;
public class MyClass {
    public static void main(String args[]) {
        String a[] = {"a","b","c"};
        String b[] = Arrays.copyOf(a, a.length);
        a[0] = "hello";
        System.out.println( Arrays.toString(a) );
        // [hello, b, c]
        System.out.println( Arrays.toString(b) );
        // [a, b, c]
    }
}
import java.util.Arrays;
public class MyClass {
    public static void main(String args[]) {
        String a[] = {"a","b","c"};
        String b[] = new String[a.length];
        System.arraycopy( a, 0, b, 0, a.length );
        a[0] = "hello";
        System.out.println( Arrays.toString(a) );
        // [hello, b, c]
        System.out.println( Arrays.toString(b) );
        // [a, b, c]
    }
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}