public class ArrayCopyTest {
	
	public static void main(String[] args) {

		int[] arr = {1, 2, 3, 4, 5};
		
		int[] arrClone = arr.clone();
		arrClone[0] = 6;
		System.out.println("arrClone");
		printArray(arrClone);
		
		int[] arrCopy = new int[arr.length];
		System.arraycopy(arr, 0, arrCopy, 0, arr.length);
		arrCopy[1] = 6;
		System.out.println("arrCopy");
		printArray(arrCopy);
	}
	
	public static void printArray(int[] arr) {
		System.out.println(java.util.Arrays.toString(arr));
	}
}

 

블로그 이미지

행복그리고..

,