Get Size of Java LinkedHashMap Example

Get Size of Java LinkedHashMap Example


Posted in : Java Posted on : December 4, 2010 at 6:02 PM Comments : [ 0 ]

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

Get Size of Java LinkedHashMap Example

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

 Example: SizeOfLinkedHashMap.java

package devmanuals.com;

import java.util.*;

public class SizeOfLinkedHashMap {
	public static void main(String args[]) {
		LinkedHashMap Lhm = new LinkedHashMap();
		Lhm.put(1, "Gyan");
		Lhm.put(6, "Ankit");
		Lhm.put(5, "Arun");
		Lhm.put(4, "Anand");
		Lhm.put(3, "Ram");
		System.out.println("The Size of LinkedHashMap are : " + Lhm.size());
		Object obj = Lhm.remove(5);
		System.out.println("The removed value is : " + obj);
		System.out.println("The size of map after removal : " + Lhm.size());
	}
}

Output:

The Size of LinkedHashMap are : 5 

The removed value is : Arun 

The size of map after removal : 4

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics