Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

System.arraycopy Method

Visual Studio 2005

Copies a specified portion of a source array, starting from a specified position, to a destination array, starting at a specified position.

Package: java.lang

Assembly: vjslib (in vjslib.dll)

public static void arraycopy(
    java.lang.Object src,
    int src_position,
    java.lang.Object dst,
    int dst_position,
    int length);



The source array object.


The position where the copying starts in the source array.


The destination array object.


The position where the copying starts in the destination array.


The length of the array's portion to be copied.

// sys-arr1.jsl
// System.arraycopy example

public class MyClass
    public static void main(String[] args)
        // Declare two arrays:
        int[] arr1 = {1,2,3,4,5,6};
        int[] arr2 = {0,2,4,6,8,10};
        // Copy two elements from arr1 starting from the second element
        // into arr2 starting at the fourth element:
                        1,       // Second element.
                        3,       // Fourth element.
                        2        // Length = 2.

        // Display the new array (arr2):
        for (int i=0; i<arr2.length; i++)
            System.out.println("Element #" + i + " = " + arr2[i]);

Element #0 = 0
Element #1 = 2
Element #2 = 4
Element #3 = 2
Element #4 = 3
Element #5 = 10

Throws java.lang.ArrayIndexOutOfBoundsException if any of the following conditions is true:

dst or src is an empty array.

src_position is negative

dst_position is negative.

length is negative.

Community Additions

© 2015 Microsoft