- import java.io.*;
- /**
- *@author Sreekandan.K
- */
- class ArrayCopyDemo
- {
- public static void main(String args[])
- {
- int[] mark1={55,77,89,91,57};
- int[] mark2={45,35,41,33,30,06};
- System.out.println("The Elements of first array are:");
- for(int i=0;i<mark1.length;i++)
- {
- System.out.println(mark1[i]);
- }
- System.out.println("The Elements of second array are:");
- for(int i=0;i<mark2.length;i++)
- {
- System.out.println(mark2[i]);
- }
- System.arraycopy(mark1,2,mark2,3,3);
- System.out.println("The Values in Second Array(mark2) after replacement are:");
- for(int i=0;i<mark2.length;i++)
- {
- System.out.println(mark2[i]);
- }
- }
- }
Java allows you to copy the value of one array into another. It can be done by using the arraycopy method of System class. It can be used as the following form:
System.arraycopy(from, fromIndex, to, toIndex, count);
- from - specifies the array name from which you want to copy.
- fromIndex - specifies the position of the array from which you want to copy.
- to - specifies the destination array name on which you want to store the values.
- toIndex - specifies the position of the destination array from which you want to store the values.
- count - specifies the number of elements that you want to copy and store.
OUTPUT
No comments:
Post a Comment
Leave the comments