Skip to content
Related Articles

Related Articles

Improve Article

LinkedList size() Method in Java

  • Difficulty Level : Basic
  • Last Updated : 10 Dec, 2018

The Java.util.LinkedList.size() method is used to get the size of the Linked list or the number of elements present in the linked list.



Parameters: This method does not take any parameter.

Return Value: This method returns the size or the number of elements present in the LinkedList.

Below program illustrate the Java.util.LinkedList.size() method:

// Java code to illustrate size()
import java.util.LinkedList;
public class LinkedListDemo {
    public static void main(String args[])
        // Creating an empty LinkedList
        LinkedList<String> list = new LinkedList<String>();
        // Using add() method to add elements in the list
        // Displaying the linkedlist
        System.out.println("LinkedList:" + list);
        // Displaying the size of the list
        System.out.println("The size of the linked list is: " 
                                                + list.size());
LinkedList:[Geeks, for, Geeks, 10, 20]
The size of the linked list is: 5

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :