arrayCopy() method of System
public static void arraycopy(Objectsource , int srcIndex,
Object dest, int destIndex, int length)
The two Object arguments indicate the source and destination array. The three integer arguments indicate the starting location in each the source and the destination array, and the number of elements to copy.
This method will copy ‘length’ number of elements of array ‘source’ starts from the location ‘srcIndex’ to the array ‘dest’ starts from ‘destIndex’.
public class ArrayCopyDemo {
public static void main(String[] args) {
char[] Src = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',
'i', 'n', 'a', 't', 'e', 'd' };
char[] dst = new char[7];
System.arraycopy(src, 2, dst, 0, 7);
System.out.println(new String(dst));
}
}
No comments:
Post a Comment