通常进行数组的复制需要使用到循环,然而jdk中已经给我们封装好了一个专门用来复制数组的快捷方法
arraycopy()
使用方法:
System.arraycopy(src, srcPos, dest, destPos, length);
注:
src:被复制的数组
srcPos:类src中开始复制的位置
dest:进行复制的数组
destPos:复制进dest的位置
length:总共复制的长度
方法应用:
/**
* 复制数组
* @author tyrantForever
*
*/
public class Test5 {
public static void main(String[] args) {
int[] nums = {1,2,3,4,4,5,6,67};
int[] nums2 = new int[5];
System.arraycopy(nums, 1, nums2, 0,4);
for(int num : nums2) {
System.out.println(num);
}
}
}
输出结果:

494

被折叠的 条评论
为什么被折叠?



