Pages

Copy all contents from one array to other array

*****************************************
COMPLETE SOURCE CODE FOR : CopyArray.java
*****************************************


public class CopyArray
{
public static void main(String[]args)
{
//Create array with it's component
String[]animal={"lion","tiger","elephant","crocodile"};

//Create empty array with size same as animal
String[]animal2=new String[animal.length];

//Copy all element in animal into animal2
System.arraycopy(animal,0,animal2,0,animal.length);

//Print all element in animal2
int temp=0;
while(temp!=(animal.length))
{
System.out.println(animal2[temp]);
temp=temp+1;
}
}
}


*****************************************
JUST COMPILE AND EXECUTE IT
*****************************************
Related Posts Plugin for WordPress, Blogger...