![]() |
VOOZH | about |
In Java, the addAll() method of the LinkedList class is used to add all the elements of one collection to another. This method takes a Collection as an argument and adds all its elements to the end of the list.
Example: Here, we use the addAll() method to add all the elements of one collection to another.
[Geeks, for, Geeks] [Geeks, for, Geeks, 10, 20]
Now there are two versions of LinkedList addAll() method i.e. one with the specified index and one without any specified index.
The addAll() method takes a Collection as an argument and adds all elements from the specified collection to the end of the current LinkedList.
Syntax:
public boolean addAll(Collection)
Parameters:
Return Type: This method returns true, if at least one action of append is performed.
Example: Here, we use addAll() method to add all the elements of one collection to another at the end of the list.
[100, 200, 300] [100, 200, 300, 400, 500, 600]
The addAll(index , Collection) method takes an index and a Collection as arguments and adds all elements from the specified collection starting at the given index. The subsequent elements are shifted to the right.
Syntax:
public boolean.addAll(index , Collection);
Parameters: This function accepts two parameters an index and Collection. The elements of the collection are inserted at the specified index in the list.
Example: Here, we use the addAll() method to add all the elements from a collection at the specified index.
[100, 200] [100, 300, 400, 200]