Share on Google+Share on Google+

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 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.


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]);


result = C
result = D
result = E


Posted on: April 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.