public static char[] copyOfRange(char[] original, int from, int to) { int newLength = to - from; if (newLength < 0) throw new IllegalArgumentException(from + " > " + to); char[] copy = new char[newLength]; System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); return copy; }
arraycopy(src,sPos,dest,dPos,length)中最后一个参数是“要复制的数组元素的数量”,那就用newLength代入了,为什么还要比较“original.length - from”和“newLength”之间谁最小值?这样做的用意是?谢谢!
波斯汪
相关分类