# What does the method addAll(Coll C)do in java?

Java 8Object Oriented ProgrammingProgramming

The addAll(Collection<? extends E> c) method of the class java.util.ArrayList 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 (implies that the behavior of this call is undefined if the specified collection is this list, and this list is nonempty).

## Example

import java.util.ArrayList;

public class ArrayListDemo {
public static void main(String args[]) {
ArrayList<Integer> arrlist = new ArrayList<Integer>(5);
System.out.println("Printing list1:");
for (Integer number : arrlist) {
System.out.println("Number = " + number);
}
ArrayList<Integer> arrlist2 = new ArrayList<Integer>(5);
System.out.println("Printing list2:");
for (Integer number : arrlist2) {
System.out.println("Number = " + number);
}
System.out.println("Printing all the elements");
for (Integer number : arrlist) {
System.out.println("Number = " + number);
}
}
}

## Output

Printing list1:
Number = 12
Number = 20
Number = 45
Printing list2:
Number = 25
Number = 30
Number = 31
Number = 35
Printing all the elements
Number = 12
Number = 20
Number = 45
Number = 25
Number = 30
Number = 31
Number = 35
Published on 16-Jan-2018 11:43:38