Skip to content
Related Articles

Related Articles

LinkedList size() Method in Java

View Discussion
Improve Article
Save Article
Like Article
  • 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!