Check an Value Is Exists in Java HashMap Example

Check an Value Is Exists in Java HashMap Example


Posted in : Java Posted on : December 2, 2010 at 5:40 PM Comments : [ 0 ]

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

Check an Value Is Exists in Java HashMap Example

This Java Example shows how to know that an Value is exists in the specified HashMap object  in java. To get the Value from HashMap object we use boolean containsValue(value) method. This method returns true if list contains the specified Value otherwise returns false.

 Example: ContainsValueInHashMap.java

package devmanuals.com;

import java.util.*;

public class ContainsValueInHashMap{
	public static void main(String args[]) {
		HashMap hm = new HashMap();
		hm.put(1, "Gyan");
		hm.put(2, "Ankit");
		hm.put(3, "Arun");
		hm.put(4, "Anand");
		hm.put(5, "Ram");
		boolean bool = hm.containsValue("Gyan");
		System.out.println("Is Gyan is exists in HashMap : " + bool);

	}
}

Output:

Is Gyan is exists in HashMap : true

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics