Arrays.copyOf()

Arrays.copyOf(원본 배열, 원본 배열에서 복사할 길이)

지정된 배열을 index 0부터 원하는 길이만큼 복사한다.

원본 배열 길이 이후의 인덱스는 배열의 타입의 기본값으로 초기화되어 copy된다.

입력한 길이 이후의 index는 제거되어 copy된다.

public static int[] copyOf(int[] original, int newLength) { 
  int[] copy = new int[newLength]; 
  System.arraycopy(original, 0, copy, 0, 
                   Math.min(original.length, newLength)); 
  return copy; 
} 

위 코드를 보면 알 수 있듯, Arrays.copyOf()는 System.arraycopy() 메서드를 래핑한 함수다.

이 둘의 차이가 있다면 다음과 같다,

Ex