Java System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Syntax
System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) has the following syntax.
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Example
In the following code shows how to use System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) method.
/*from w ww . j ava 2 s. c o m*/
public class Main {
public static void main(String[] args) {
int arr1[] = { 0, 1, 2, 3, 4, 5 };
int arr2[] = { 0, 10, 20, 30, 40, 50 };
// copies an array from the specified source array
System.arraycopy(arr1, 0, arr2, 0, 1);
System.out.print("array2 = ");
System.out.print(arr2[0] + " ");
System.out.print(arr2[1] + " ");
System.out.print(arr2[2] + " ");
System.out.print(arr2[3] + " ");
System.out.print(arr2[4] + " ");
}
}
The code above generates the following result.