package com.snape.java._5th.Test61; public class ArrayCopy { public static void main(String[] args) { int[] arr1 = {1,2,3,4,5,6,7,8,9}; int[] arr2 = new int[arr1.length]; System.arraycopy(arr1,0,arr2,0,arr1.length); System.out.println("原数组:"); arrayPrint(arr1); System.out.println("--------------------------"); System.out.println("复制得到的数组:"); arrayPrint(arr2); } //打印数组 public static void arrayPrint(int[] arr){ for(int i : arr){ System.out.print(i + "\t"); } System.out.println(); } }
结果: