System.arrayCopy的使用
首先看一下声明,这是一个native方法:
Object[] array3 = new Object[] { 1, null, 3, 4.4, 5.1 };Integer[] array4 = new Integer[5];// ArrayStoreException would be thrown for copying the array whose component type is reference type// to the one whose component type is primitive type// int array 4 = new int[5];try {System.arraycopy(array3, 0, array4, 0, array3.length);} catch (ArrayStoreException e) {e.printStackTrace(); // java.lang.ArrayStoreException}System.out.println(Arrays.toString(array4)); // [1, null, 3, null, null]