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 |
[ 0 ] Comments