Java ArrayList addAll Example
ArrayList class addAll method example. This example shows you how to use addAll method.
ArrayList class addAll method example.public boolean addAll(Collection c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.
Here is the code
/**
* @ # AddAll.java
* A class repersenting use to addAll(collection c)
* method of ArrayList class in java.util package
* version 14 May 2008
* author Rose India
*/
import java.util.*;
public class AddAll {
public static void main(String args[]) {
List arrlist = new ArrayList();
List arrlist1 = new ArrayList();
int i = 0;
String str = "Rose India";
//Add the specified element to the end of this list.
arrlist.add(i);
arrlist.add(str);
System.out.println("arrlist = " + arrlist);
//Add the specified element to the end of this list.
arrlist1.add("Rose");
arrlist1.add("India");
System.out.println("arrlist1 = " + arrlist);
//Appends all of the elements in the specified collection to the end of this list
arrlist.addAll(arrlist1);
System.out.println("arrlist = " + arrlist);
}
} |
Output
arrlist = [0, Rose India]
arrlist1 = [0, Rose India]
arrlist = [0, Rose India, Rose, India] |
|