/**
*
* <b>Application name:</b><br>
* <b>Application describing:数组拷贝操作</b> <br>
*/
public class ArrayCopy
{
/**
*
* {方法功能中文描述}
*
* @param args
*/
public static void main(String[] args)
{
int[] arr = new int[] { -10, 2, 3, 246, -100, 0, 5 };
int[] dstArr=new int[arr.length-1];
//数组长度是不可变的,删除数组中的元素,其实要进行拷贝操作
System.arraycopy(arr, 0, dstArr, 0, 3);//拷贝0-2
System.arraycopy(arr, 4, dstArr, 3, 3);//拷贝4-6
for(int i=0;i<dstArr.length;i++)
{
System.out.print(dstArr[i]+",");
}
//可以看出System.arraycopy非常适合做连续元素的拷贝,如果元素是不连续的,可以考虑用for循环。
}
}
Java 数组的拷贝
最新推荐文章于 2025-12-01 18:34:47 发布
419

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



