VOOZH about

URL: https://www.geeksforgeeks.org/java/java-util-linkedlist-addall-method-in-java/

⇱ LinkedList addAll() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList addAll() Method in Java

Last Updated : 11 Jul, 2025

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.


Output
[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.

1. addAll(Collection)

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:

  • list is the current LinkedList.
  • Collection is the group of items whose elements will be added to the end of the current list.

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.


Output
[100, 200, 300]
[100, 200, 300, 400, 500, 600]

2. addAll(index , Collection)

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.


Output
[100, 200]
[100, 300, 400, 200]
Comment