Java arraycopy example- 1


 

Java arraycopy example- 1

This tutorial demonstrate the arraycopy method. In the below listed program you will see how arraycopy method is help in copy one array variable's values into a new array variable. 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.

This tutorial demonstrate the arraycopy method. In the below listed program you will see how arraycopy method is help in copy one array variable's values into a new array variable. 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:

class DisplyaArrayCopy {
  DisplyaArrayCopy() {
    int[] intArray = new int[] { 1234};
    int[] arrayCopy = new int[intArray.length];
    System.arraycopy(intArray, 0, arrayCopy, 0, intArray.length);
    for (int i = 0; i < arrayCopy.length; i++)
      System.out.println(arrayCopy[i]);
  }
}

public class ArrayCopyExample {
  public static void main(String[] args) {
    new DisplyaArrayCopy();
  }
}

Output:

1
2
3
4
5

Ads