废话不多说,直接上代码!
public class KaoBei {
//数组的拷贝用到的静态方法: System.arraycopy();
public static void main(String[] args) {
//数组的静态初始化
int[] a1 = {1, 2, 3, 4};
//数组的动态初始化
int[] a2 = new int[15];
//System.arraycopy(源数组名,源数组的起始位置,目标数组名,目标数组的起始位置,拷贝的长度);
System.arraycopy(a1, 0, a2, 8, 4);
//for循环遍历输出拷贝后的数组
for (int j : a2) {
System.out.print(j + "\t");
}
}
}
执行结果: