Menu
Topics Index
...
`

ArrayCopyDemo1 - Java Example Program


ArrayCopyDemo1
class ArrayCopyDemo1
{
    public static void main(String arg[])
    {
        char array[] = {'J', 'a', 'v', 'a', 'i', 's', 'f', 'u', 'n'};
        char arrayCopy[] = new char[4];
        System.arraycopy(array, 0, arrayCopy, 0, 4);
        // Print characters as a string
        System.out.println(new String(arrayCopy));    
    }
}
OUTPUT

Java

DESCRIPTION

THINGS TO TRY
  • In the above program, change the last argument of arraycopy() from 4 to 3 or 2 and observe the change in the output.

© meritcampus 2019

All Rights Reserved.

Open In App