Home » Java programming language

Java LinkedList int size() method with Example

Java LinkedList int size() method: Here, we are going to learn about the int size() method of LinkedList class with its syntax and example.
Submitted by Preeti Jain, on June 24, 2019

LinkedList int size() method

  • This method is available in package java.util.Collection and here, Collection is an interface.
  • This method is declared in interface Collection and implemented by the LinkedList Class.
  • This method is used to check how many elements exist in the Linked list or return the size of the Linked list.


    int size(){


This method does not accept any parameter of the Linked List.

Return value:

The return type of this method is int that means this method returns the size of the list or number of elements exists in the LinkedList.

Java program to demonstrate example of LinkedList size() method

import java.util.LinkedList;

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

        // Create an object of linked list 
        LinkedList list = new LinkedList();

        // use add() method to add few elements in the linked list 

        //  Current Linked list Output
        System.out.println("The  Current Linked List is :" + list);

        // With the help of size() we will check 
        // how many elements exists in the linked list. 

        System.out.println("The size() of the list is  : " + list.size());


D:\Programs>javac LinkList.java

D:\Programs>java LinkList
The  Current Linked List is :[10, 20, 30, 40, 50]
The size() of the list is  : 5

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.