Home Tutorial Java Collections Arraylist Java ArrayList Addall

 
 

Share on Google+Share on Google+
Java ArrayList Addall
Posted on: October 23, 2009 at 12:00 AM
Advertisement
This section demonstrates how to use the addAll() method in Java Arraylist.

  • It adds all the elements of the second list at the end of the given first list.


Java Arraylist Addall Example


import java.util.*;

public class List1 {

public static void main(String[] args) {
String  ar[]={"india","pakistan","United Kingdom","Japan"};
List list=new ArrayList();
list.add(ar[0]);
list.add(ar[1]);
list.add(ar[2]);
list.add(ar[3]);

List list1=new ArrayList();
list1.add("delhi");
list1.add("islamabad");
list1.add("britain");
list1.add("tokyo");
System.out.println(list);
list.addAll(list1);
System.out.println(list);

}
}
[india, pakistan, United Kingdom, Japan]
[india, pakistan, United Kingdom, Japan, delhi, islamabad, britain, tokyo]

Advertisement

Related Tags for Java ArrayList Addall:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com