Copying Arrays
Array copy means copying the elements of the array or a part of the array. We have to declare the array in which elements are to copied of the same size as that of the original array.
/*
http://www.ProbCOMP.com
Array copy means copying the elements of the array or a part of
the array. We have to declare the array in which elements are to copied
of the same size as that of the original array.
*/
public class CopyingArray{
public static void main(String args[])
{
int[] originalArray = {1,2,3,4,5};
int[] copyArray = new int[5];
System.arraycopy(originalArray, 0, copyArray, 0, originalArray.length);
System.out.println("Original Array");
for (int i=0; i < originalArray.length; i++) {
System.out.println(originalArray[i]);
}
System.out.println("\nCopy Array");
for (int i=0; i < copyArray.length; i++) {
System.out.println(copyArray[i]);
}
}
}
Download Program


