CKTIS / Java
System.arraycopy — copying an array range
System.arraycopy copies elements into an existing array, supporting overlapping ranges while requiring compatible types and valid bounds.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
System.arraycopy(src, srcPos, dest, destPos, length);System.arraycopy copies length elements from src at srcPos into existing array dest at destPos. It returns void, not a new array.
Overlapping ranges work as though using temporary storage. Values, including references, are copied—not objects themselves.
Primitive types must match exactly. null causes NullPointerException; invalid bounds or negative length cause IndexOutOfBoundsException. Non-array arguments or incompatible types cause ArrayStoreException.
An incompatible reference element can leave earlier elements copied; bounds errors and array-category mismatches leave the destination unchanged.
Examples
public class Main {
public static void main(String[] args) {
int[] values = {1, 2, 3, 4};
System.arraycopy(values, 0, values, 1, 3);
for (int value : values) {
System.out.println(value);
}
}
}Result
1 1 2 3
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.