java使用Sytem.arraycopy方法复制数组,,System类的静态方法
分享于 点击 25313 次 点评:33
java使用Sytem.arraycopy方法复制数组,,System类的静态方法
System类的静态方法arraycopy可以复制数组,此方法有5个参数,
指定要复制的数组复制开始索引目标数组目标数组的复制开始索引复制数组的元素数下面是测试代码:
/** * * @author cn.outofmemory */public class Main { /** * Copies an array of int values to another array */ public void copyArrayExample() { int[] intArray = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int[] arrayCopy = new int[intArray.length]; System.arraycopy(intArray, 0, arrayCopy, 0, intArray.length); for (int i = 0; i < arrayCopy.length; i++) System.out.println(arrayCopy[i]); } /** * @param args the command line arguments */ public static void main(String[] args) { new Main().copyArrayExample(); }}
输出:
1234567890
用户点评