Question Detail

How Merge Two Array in Java ?

5 years ago Views 1363 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

- 5 years 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

- 5 years 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));