Get Size of Java LinkedList Example

Get Size of Java LinkedList Example


Posted in : Java Posted on : November 29, 2010 at 5:37 PM Comments : [ 0 ]

This Java Example shows how to get the Number of elements in the LinkedList object i.e size of LinkedList object in java.

Get Size of Java LinkedList Example

This Java Example shows how to get the Number of elements in the LinkedList object  i.e size of LinkedList object in java. To get no. of element in the LinkedList object we use int size() method. This method returns number of the elements in the specified LinkedList object.

 Example: SizeOfLinkedList.java

package devmanuals.com;

import java.util.*;

public class SizeOfLinkedList {
	public static void main(String[] args) {
		LinkedList LKLST = new LinkedList();
		LKLST.add("1");
		LKLST.add("2");
		LKLST.add("3");
		LKLST.add("4");
		LKLST.add("5");
		System.out.println("The Linked List is as : " + LKLST);
		int a = LKLST.size();
		System.out.println("The Linked List Size is : " + a);

	}
}

Output:

The Linked List is as : [1, 2, 3, 4, 5] 

The Linked List Size is : 5

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics