Check an Key Is Exists in Java TreeMap Example

Check an Key Is Exists in Java TreeMap Example


Posted in : Java Posted on : December 3, 2010 at 5:25 PM Comments : [ 0 ]

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

Check an Key Is Exists in Java TreeMap Example

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

 Example: ContainskeyInTreeMap.java

package devmanuals.com;

import java.util.*;

public class ContainskeyInTreeMap {
	public static void main(String args[]) {
		TreeMap Tmap = new TreeMap();
		Tmap.put("Gyan", "Singh");
		Tmap.put("Ankit", "Kumar");
		Tmap.put("Arunesh", "Kumar");
		Tmap.put("Anand", "Nagar");
		Tmap.put("Ram", "Prakash");
		boolean bool = Tmap.containsKey("Arunesh");
		System.out.println("Is Arunesh is exists in map : " + bool);
	}
}

Output:

Is Arunesh 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