Java ArrayList addAll() methodLast Updated : 17 Mar 2025 Java ArrayList addAll(Collection c) methodThe addAll (Collection c) method of Java ArrayList classappends all of the elements in the specified collection to the end of this list. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. Syntax:Parameter:"c": is the Collection that contained elements to be added to this list. Return:Return "true": if the collection "c" has been appended successfully to the original list. Exception:java.lang.NullPointerException: If the specified collection "c" is null. Example 1Output: [A, B, C] [Apple, Ball, Cat] true [A, B, C, Apple, Ball, Cat] Example 2Output: [Apple, Banana, Orange] Java ArrayListaddAll(int index, Collection c) methodThe addAll (int index, Collection c) method of Java ArrayList classinserts all of the elements in the specified collectioninto this list starting at the specified index. It shifts the element currently at that position and any subsequent elements to the right. The new elements will appear in the list in the order that they are returned by the specified collection?s iterator. Syntax:Parameter:"index":The position at which to insert the first element of the specified list. "c": is the Collection that contained elements to be added to this list. Return:Return "true": If the collection "c" has been inserted successfully to the original list. Exception:java.lang.NullPointerException: If the specified collection "c" is null. java.lang.IndexOutOfBoundsException: If the index is out of range. Example 3Output: [A, B, C] [Adel, Ahmed, Ali] true [A, Adel, Ahmed, Ali, B, C] Example 4Output: [1, 2, 3] 3 java.lang.IndexOutOfBoundsException: Index: 4, Size: 3 Example 5Output: [1, 2, 3] 3 java.lang.NullPointerException Next TopicJava ArrayList |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India