boolean addAll(Collection c)
This method is used to append all the elements identified by the collection
c at the end of the list, in the same order returned by the collection's iterator.
Parameters: This method accepts a mandatory parameter
c which is the collection containing the elements, which are to be appended at the end of the list.
Return Value: This method returns a boolean value. It returns true if the collection is inserted correctly into the list, otherwise, it returns false.
Exception: This method throws
NullPointerException if the specified element is null.
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
boolean addAll(int index, Collection c)
This method is to add the elements of one collection into another list. Insertion of elements will start from the stated index. Elements will be added as per the order returned by the collection's iterator. Element which was previously present at that index(if any) will move to right when a new element is added.
Parameters :
index is the position at which elements of collection will be inserted.
c is the collection containing the elements, which are to be appended at the end of list.
Return Value :Its return type is boolean. It returns true if the collection is inserted correctly into the list at the stated index, otherwise, it returns false.
Exception :
NullPointerException - if the specified collection is null.
IndexOutOfBoundsException - if the specified index is out of range.