— 数组A:1、2、3、4、5、6、7、8;
— 数组B:11、22、33、44、55、66、77、88;
— 将数组A的部分内容替换到数组B中,数组B的最终结果为:11、22、5、6、7、66、77、88。
代码如下:
public class ArrayDemo {
public static void main(String args[]) {
int dataA[] = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; // 定义数组
int dataB[] = new int[] { 11, 22, 33, 44, 55, 66, 77, 88 };// 定义数组
System.arraycopy(dataA, 4, dataB, 2, 3); // 数组复制
print(dataB);
}
public static void print(int temp[]) { // 打印数组内容
for (int x = 0; x < temp.length; x++) {
System.out.print(temp[x] + "、");
}
System.out.println();
}
}