Click here to Skip to main content
15,443,631 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have created a java program in which a array of int data type containing 5 Element like 10,15,20,25,30 and want to copying all the same data into Another array without putting same value.
any help please...
Posted

Hey you can do it by using Clone Method for copying same element

as

C#
int[] arr1 = { 10, 15, 20, 25, 30 };
          int[] arr2 = (int[])arr1.Clone();  // Using Clone
          for (int i = 0; i < arr2.Length; i++)
          {
              System.out.println(arr2[i].ToString()); // Print arr2 value
          }
          Console.ReadLine();


when you compile and interprets this program you will notice that arr2 will display all element of arr1
 
Share this answer
 
Comments
AshishKr 24-Oct-10 11:44am    
Thanks it works for me..
Well if you want the 2nd array to be a copy, then by definition it should have the same elements in the same order. Otherwise you are just creating a new array with some arbitrary elements in it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900