GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Java ArrayList addall() Method with Example - GeeksforGeeks Java ArrayList addall() Method with ExampleLast Updated : 20 Jul, 2026 The addAll() method of the ArrayList class is used to add all elements from a specified collection to an ArrayList. It supports adding elements either at the end of the list or at a specified index, making it useful for merging collections or inserting multiple elements in a single operation.
Output [Java, C++, C] Explanation: The addAll() method appends all elements of l2 to the end of l1 while preserving their order. 1. boolean addAll(Collection c)This version appends all elements of the specified collection to the end of the ArrayList. Syntax:
Output Final ArrayList: [10, 20, 30, 40] Explanation: In this example, two ArrayList<Integer> objects are created. The first list (l1) contains 10 and 20, while the second list (l2) contains 30 and 40. Calling l1.addAll(l2) appends all elements of l2 to the end of l1, resulting in the combined list [10, 20, 30, 40]. 2. boolean addAll(int index, Collection c)This version inserts all elements from the specified collection into the ArrayList at the specified index. It shifts the current elements and subsequent elements to the right. Syntax:
Parameters:
Output [Java, C++, C, AI, Python] Explanation: In this example, the first ArrayList (l1) contains "Java", "C++", and "Python", while the second list (l2) contains "C" and "AI". The addAll(2, l2) method inserts all elements of l2 starting at index 2. The existing element "Python" is shifted to the right, resulting in the list [Java, C++, C, AI, Python]. Advantages of ArrayList.addAll() Method
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |