好奇心鞭策着你成长!
1、
/** * @param src(原数组) * the source array to copy the content. * @param srcPos(源数组中的起始位置) * the starting index of the content in {@code src}. * @param dst(目标数组) * the destination array to copy the data into. * @param dstPos(目标数据中的起始位置) * the starting index for the copied content in {@code dst}. * @param length(要复制的数组元素的数量) * the number of elements to be copied. * */ byte[] srcBytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; byte[] dstBytes = new byte[5]; System.arraycopy(srcBytes, 0, dstBytes, 0, dstBytes.length); System.out.println(Arrays.toString(dstBytes));2、想用集合(List)测试下,不行,报错如下:
Caused by: java.lang.ArrayStoreException: source of type java.util.ArrayList is not an array
后来看到一篇说到List.add和remove的方法的源码,也是用到System.arraycopy,可以研究研究
3、