Friday, 20 March 2015

How To Copy Array In Java

This tutorial illustrate an another method of array which is used to copy data from one array to another its general form is shown below
public static void arraycopy(Object src, int srcPos,Object dest, int destpos, int length)
here src object specify from where array is to be copied whereas dest object specify where to be copied.And int src specify starting postion of array and int destpos specify starting index of destination array int length shows length of character to be copied.

CODING:


class arraycopy
{
public static void main(String args[])
{
char[] From = { 'd', 'j', 'a', 'v', 'a', 'e',
'i', 'n', 'a' };
char[] To = new char[7];

System.arraycopy(From, 1, To, 0, 4);
System.out.println(new String(To));
}
}

OUTPUT:


No comments:

Post a Comment