Java arraycopy example- 2


 

Java arraycopy example- 2

An arraycopy method in java copies an array from the specified source array, beginning or from the specified position, to the specified position of the destination array.

An arraycopy method in java copies an array from the specified source array, beginning or from the specified position, to the specified position of the destination array.

Description:

An arraycopy method have the following parameters.
arraycopy(Object source, int srcPositon, Object destination, int destPosition, int length). Here in this tutorial you will see a simple example of the arraycopy method of java.

Code:

public class ArrayCopyExample {
  public static void main(String[] args) {
    String[] characters = "A""B""C""D""E" };
    String[] copiedinto = new String[3];
    System.arraycopy(characters, 2, copiedinto, 03);
    for (int i = 0; i < copiedinto.length; i++) {
      System.out.println("result = " + copiedinto[i]);
    }
  }
}

Output:

result = C
result = D
result = E

Ads