System.arraycopy()
public static void main(String[] args) {
/*List l = new ArrayList<String>(10);
l.add(3, "ed");*/
int[] src = {1,2,3,4,5,6,7};
int[] dest = new int[7];
int srcPos = 0;
int destPos = 3;
int length = 3;
//将src数组的srcPos到srcPos+length-1处的元素移植到src数组的index等于destPos开始的索引处到destPos+length-1处
//将src数组的0到2处的元素移植到src数组的index等于3开始的索引处
System.arraycopy(src, srcPos, src, destPos, length);
for(int i : src){
System.out.println(i);
}
System.out.println("++++++++");
int[] src2 = {1,2,3,4,5,6,7};
int[] dest2 = new int[7];
int srcPos2 = 0;
int destPos2 = 3;
int length2 = 3;
System.arraycopy(src2, srcPos2, dest2, destPos2, length2);
for(int i : dest2){
System.out.println(i);
}
}
一步一个脚印,方便自己复习,欢迎大家指正,非常感谢,共同进步!
posted on 2013-11-22 14:59 lovebeauty 阅读(248) 评论(0) 编辑 收藏 举报