how does addall work in java code example
Example: ArrayList addAll(int index, Collection c) method in java
import java.util.ArrayList;
public class ArrayListAddAllMethod
{
public static void main(String[] args)
{
ArrayList<Integer> al1 = new ArrayList<Integer>(5);
al1.add(11);
al1.add(13);
al1.add(15);
System.out.println("ArrayList 1 elements: ");
for(Integer number : al1)
{
System.out.println("Number: " + number);
}
ArrayList<Integer> al2 = new ArrayList<Integer>(5);
al2.add(12);
al2.add(14);
al2.add(16);
al2.add(18);
System.out.println("ArrayList 2 elements: ");
for(Integer number : al2)
{
System.out.println("Number: " + number);
}
al1.addAll(2, al2);
System.out.println("Print all elements: ");
for(Integer number : al1)
{
System.out.println("Number: " + number);
}
}
}