Home  >  Forum  >  Core Java
Post New Query

Example of Java ArrayList class in Collection to add two ArrayList



Asked on March 01, 2015
Hi people ant plz send me any code by which I can add two arraylist in collection of java.


Replied on March 01, 2015
Using addAll() you can add two ArryList in collection of Java. See the below example...

package programs;

import java.util.ArrayList;
import java.util.Iterator;

public class CollectionTestAddAll {
public static void main(String[] args) {
ArrayList<String> alist1= new ArrayList<String>();
alist1.add("Atul");
alist1.add("Diksha");
alist1.add("Anand");
alist1.add("Sunandan");
ArrayList<String> alist2 = new ArrayList<String>();
alist2.add("Kumud");
alist2.add("A.K Yadav");
alist1.addAll(alist2);
Iterator itr = alist1.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
}

}



Write Answer







©2019 concretepage.com | Privacy Policy | Contact Us