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


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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM