首页 > 编程语言 > 详细

3分钟了解Java中System.arraycopy的用法

时间:2019-08-29 12:38:29      阅读:80      评论:0      收藏:0      [点我收藏+]

System提供了一个静态方法arraycopy(),我们可以使用它来实现数组之间的复制。其函数原型是:

public static native void arraycopy(Object?src,int?srcPos,Object?dest, int?destPos,int?length);
* @param      src      the source array. 源数组
* @param      srcPos   starting position in the source array. 源数组的起始位置
* @param      dest     the destination array. 目标数组
* @param      destPos  starting position in the destination data. 目标数组的起始位置
* @param      length   the number of array elements to be copied. 复制的长度

举个栗子:

将array数组复制到新的数组中;

int[] array = {1, 2, 3, 4, 5};
int[] targetArr = new int[array.length];
System.arraycopy(array,0,targetArr,0,array.length);

3分钟了解Java中System.arraycopy的用法

原文:https://www.cnblogs.com/benjieqiang/p/11428832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!