System.arraycopy

This commit is contained in:
seahi 2024-11-10 21:23:39 +08:00
parent 66c059eb0f
commit 57e12cb859

View File

@ -0,0 +1,19 @@
package chapter5;
/**
* 拷贝数组
* System.arraycopy()
*/
public class Example10 {
public static void main(String[] args) {
int[] srcArray = {10 ,11, 12, 13, 14, 15, 16};
int[] toArray = {20, 21, 22, 23, 24, 25, 26, 27};
System.arraycopy(srcArray, 2, toArray, 3, 4);
System.out.println("拷贝后的数组元素为:");
for (int i = 0; i < toArray.length; i++) {
System.out.println("i : " + toArray[i]);
}
}
}