1、arrays.copy
public static char[] copyOf(char[] original, int newLength) {
char[] copy = new char[newLength];
System.arraycopy(original, 0, copy, 0,
Math.min(original.length, newLength));
return copy;
}
然后接着看,System.arraycopy函数:
public static native void arraycopy(Object src, int srcPos,
Object dest, int destPos,
int length);
它竟然是一个本地方法,所以,Arrays.copy 绝对是一个新的对象
本文详细解析了Java中Arrays类的copyOf方法,展示了如何通过该方法创建一个新数组,并拷贝原有数组的部分或全部元素到新数组中。同时,还深入探讨了System.arraycopy这一本地方法的应用。
28万+

被折叠的 条评论
为什么被折叠?



