Menu
Topics Index
...
`

ArrayCopyDemo2 - Java Example Program


ArrayCopyDemo2
class ArrayCopyDemo2
{
    public static void main(String arg[])
    {
        int array[] = {5, 1, 4, 9, 6, 2};
        int arrayCopy[] = new int[4];
        System.arraycopy(array, 0, arrayCopy, 0, arrayCopy.length);  // LINE A
        for (int e : arrayCopy)
            System.out.print(e + " ");    
    }
}
OUTPUT

5 1 4 9

DESCRIPTION

THINGS TO TRY
  • Make a change to the second argument of arraycopy() such that the destination array, arrayCopy here, will have elements {1, 4, 9, 6}.

© meritcampus 2019

All Rights Reserved.

Open In App