Home » Java programming language

Java LinkedList boolean addAll(Collection c) method with Example

Java LinkedList boolean addAll(Collection c) method: Here, we are going to learn about the boolean addAll(Collection c) method of LinkedList class with its syntax and example.
Submitted by Preeti Jain, on June 16, 2019

LinkedList boolean addAll(Collection c) method

  • This method is available in package java.util.Collection and here, Collection is an interface.
  • This method is declared in Collection interface and it is implemented by LinkedList class.
  • In this method Collection parameter is the list of elements whose need to insert at the end of LinkedList whether Collection is of ArrayList, LinkedList type, etc.
  • This method is used to insert the collection of objects at the end of the linked list.
  • Index position starts from 0.


    boolean addAll(Collection c){


We can pass only one argument as a parameter in the method and the Collection parameter is the collection of elements will append at the ending position of the linked list.

Return value:

The return type of this method is boolean that means this method returns true during execution of at least inserting of one element.

Java program to demonstrate example of LinkedList addAll(Collection c) method

import java.util.LinkedList;
import java.util.ArrayList;

public class LinkList {
 public static void main(String args[]) {

  // Creating a LinkedList 
  LinkedList list = new LinkedList();

  // Use add() method to add objects 
  // in the LinkedList

  // Creating a Collection ArrayList 
  // object of ArrayList Type
  ArrayList al = new ArrayList();

  // Displaying the Current LinkedList 
  System.out.println("The Current LinkedList is: " + list);

  // Appending the collection ArrayList to the LinkedList 
  // and ArrayList will start inserting elements from Fifth 
  // Position 

  //  Displaying the new LinkedList
  System.out.println("The new linked list is: " + list);


D:\Programs>javac LinkList.java

D:\Programs>java LinkList
The Current LinkedList is: [J, A, V, A]
The new linked list is: [J, A, V, A, P, R, O, G, R, A, M, M, I, N, G]

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.