Check an Key Is Exists in Java LinkedHashMap Example

Check an Key Is Exists in Java LinkedHashMap Example


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

This Java Example shows how to know that an Key is exists in the specified LinkedHashMap object in java.

Check an Key Is Exists in Java LinkedHashMap Example

This Java Example shows how to know that an Key is exists in the specified LinkedHashMap object  in java. To get the Key from LinkedHashMap object we use boolean containsKey(key) method. This method returns true if list contains mapping for the specified key otherwise returns false.

 Example: ContainskeyInLinkedHashMap.java

package devmanuals.com;

import java.util.*;

public class ContainskeyInLinkedHashMap {
	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");
		boolean bool = Lhm.containsKey(5);
		System.out.println("The Entries of LinkedHashMap are : " + Lhm);
		System.out.println("Is Key 5 is exists in map : " + bool);
	}
}

Output:

The Entries of LinkedHashMap are : 

{1=Gyan, 6=Ankit, 5=Arun, 4=Anand, 3=Ram} 

Is Key 5 is exists in map : true

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics