package com.bj.javase0;
public class Test01 {
public static void main(String[] args) {
Copy c1 = new Copy();
int[] src = {1,2,3,4,5,6,7,8,9};
int[] dest = {10,11,12,13,14,15,16};
//调用拷贝方法
c1.copy(src, 3, dest, 2, 3);
System.out.print("[ ");
for(int i = 0;i < dest.length;i++) {
if(i == dest.length-1) {
System.out.print(dest[i] + " ]");
}else {
System.out.print(dest[i] + " ,");
}
}
}
}
class Copy{
public Copy() {
}
//拷贝方法,参数列表与SUN公司提供的System.arraycopy(.......)括号中的意义相似
public void copy(int[] src,int srcPos,int[] dest,int destPos,int length) {
int j = destPos;
int count = 1;
for(int i = srcPos;i < src.length; i++) {
if(count <= length) {
dest[j] = src[i];
j++;
count++;
}else {
return ;
}
}
}
}