tan*_*ens 64
你可以用Arrays.copyOfRange()
它.
Boz*_*zho 14
Arrays.copyOfRange()
在Java 1.6中引入.如果您有旧版本,则内部使用System.arraycopy(...)
.以下是它的实现方式:
public static <U> U[] copyOfRange(U[] original, int from, int to) {
Class<? extends U[]> newType = (Class<? extends U[]>) original.getClass();
int newLength = to - from;
if (newLength < 0) {
throw new IllegalArgumentException(from + " > " + to);
}
U[] copy = ((Object) newType == (Object)Object[].class)
? (U[]) new Object[newLength]
: (U[]) Array.newInstance(newType.getComponentType(), newLength);
System.arraycopy(original, from, copy, 0,
Math.min(original.length - from, newLength));
return copy;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
51797 次 |
最近记录: |