on 07-31-2009 5:34 PM
Hi,
I have one String array.
I need to create another String array with the content of 1st array and additional 1st element in the 2nd array with "Product" text.
2nd array[0] = Product;
How do i do it
Thanks
Hey
The System class has a arraycopy method which you can use
System.arraycopy();
Please look in Google for different parameters which are required for this.
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html
Thanks
Aamir
Edited by: Aamir Suhail on Jul 31, 2009 11:45 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
String[] array1 = {"1", "2", "3"};
String[] array2 = {"4", "5"};
String[] array3 = new String[array1.length+array2.length];
System.arraycopy(array1, 0, array3, 0, array1.length);
System.arraycopy(array2, 0, array3, array1.length, array2.length);
here, the array3 will have all the elements in order ie, 1,2,3,4,5.
In case you need to use array2, assign array3 to array2 ie, array2 = array3
Hope that helps.
Regards,
Sumant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Pls, try with the following code:
String[] array1 = {"1","2","3"};
String[] array2 = new String[array1.length + 1];
array2[0] = "Product";
for(int i = 0; i < array1.length ; i++)
array2[i+1] = array1<i>;
Regards
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.