Question Detail

How Merge Two Array in Java ?

6 months ago Views 192 Visit Post Reply

I have two arrays , data in first array is predefined and data in second array is coming from the data base (data which user want to add ). How i can do this ?


Thread Reply

Hemant Sharma

- 6 months ago

String fruit[] = { "Apple", "Bannana", "Ice" };
String hitech[] = { "Bike", "Car", "Mobile" };
List list = new ArrayList(Arrays.asList(hitech));
list.addAll(Arrays.asList(fruit));
Object[] myArray = list.toArray();
System.out.println("@@@@@@@@@@@@@@@@@@@"+Arrays.toString(myArray));

Hemant Sharma

- 6 months ago

String fruit[] = { "Apple", "Bannana", "Ice" };
String hitech[] = { "Bike", "Car", "Mobile" };
List list = new ArrayList(Arrays.asList(hitech));
list.addAll(Arrays.asList(fruit));
Object[] myArray = list.toArray();
System.out.println("@@@@@@@@@@@@@@@@@@@"+Arrays.toString(myArray));