Home  >  Forum  >  Core Java
Post New Query

Example of Java ArrayList class in Collection to add two ArrayList


joined on
February 03,2015
Asked on March 01,2015
Hi people ant plz send me any code by which I can add two arraylist in collection of java.
joined on
March 15,2013
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



Sitewide-Feb4of4234x60





Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us