In the below example I have described "how to add or merge two array list?". Here I have created two array String a[],String b[], then I have initialize values in array . After this I have created arrayList and merge value String a[] and String b[]. You can see below program it will clearly describe you How to Merge two array list.
public class Add {
public static void main(String args[]){
String a[] = {"a", "b", "c"};
String b[] = {"d", "e","f","g" };
List<String> list = new ArrayList<String>(Arrays.asList(a));
// here merge String a[], String b[] values
list.addAll(Arrays.asList(b));
Object [] c = list.toArray();
System.out.println(Arrays.toString(c));
}
}
output : [a, b, c, d, e, f, g]
0 Comment(s)