How to count number of element in LinkedList

We can count number of element in LinkedList with the help of Size() Method . LinkedList size() method return number of element in the LinkdeList .

import java.util.LinkedList;

public class CountElement {

public static void main(String[] args) {

LinkedList<String> linkedList = new LinkedList<String>();

//print linkedlist
System.out.println("Before Remove Element Linklist is = "+linkedList);

//Returns the number of elements in this list.
System.out.println("number of element in linkedlist = "+linkedList.size());




Before Remove Element Linklist is = [Mumbai, Delhi, Noida, Gao, Patna]

number of element in linkedlist = 5

In this example we have seen how to count number of element in LinkedList. you can read java collection framework example about arraylist , set , map etc.


Leave a Reply

Your email address will not be published. Required fields are marked *

− 4 = 4