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. (This implies that the behavior of this call is undefined if the specified collection is this list, and this list is nonempty.)
Inserts all of the elements in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator.
Example of: addAll(Collection<? extends E> c)

package com.logicbig.example.arraylist;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class AddAllExample {
public static void main(String... args) {
// Add all elements from another collection
ArrayList<String> list1 = new ArrayList<>(Arrays.asList("A", "B"));
List<String> list2 = Arrays.asList("C", "D", "E");
list1.addAll(list2);
System.out.println("Combined list: " + list1);
}
}
Output
Combined list: [A, B, C, D, E]
JDK 25Example of: addAll(int index, Collection<? extends E> c)

package com.logicbig.example.arraylist;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class AddAllExample2 {
public static void main(String... args) {
// Insert collection at specific position
ArrayList<String> list = new ArrayList<>(Arrays.asList("A", "D", "E"));
List<String> toInsert = Arrays.asList("B", "C");
list.addAll(1, toInsert);
System.out.println("After insertAll: " + list);
}
}
Output
After insertAll: [A, B, C, D, E]
JDK 25