public static void main(String[] args) throws Exception{int[] nums = new int[]{1,2,3,4,5,6,7,8,9,10,11};System.arraycopy(nums, 5, nums, 0,nums.length - 5);System.out.println(Arrays.toString(nums));}
输出:[6, 7, 8, 9, 10, 11, 7, 8, 9, 10, 11]
注:由于仅拷贝第五位到最后一位,故而只有前面的元素改变,后边的元素没有变化,如果只想保留拷贝部分,也可以用以下方法:
public static void main(String[] args) throws Exception{int[] nums = new int[]{1,2,3,4,5,6,7,8,9,10,11};int[] copyNums = new int[6];System.arraycopy(nums, 5, copyNums, 0,copyNums.length);System.out.println(Arrays.toString(copyNums));}
输出:[6, 7, 8, 9, 10, 11]
