int [] src=new int[]{1,2,3,4,5,6,7,8,9,10};
int [] dest=new int[6];
System.arraycopy(src, 2, dest, 5, 1);
//从src中的第2个位置到dest的第5个位置;总数为1个
dest=Arrays.copyOfRange(src, 2, 4);
//从src中的第2个位置到第4个位置;总数为2个 2=obj<4
for(int value:dest){
System.out.println(value);
}
Java数组操作与遍历示例
本文展示了Java中使用System.arraycopy和Arrays.copyOfRange方法进行数组元素复制与截取的操作,并通过for-each循环遍历并打印数组元素的实现过程。
690

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



