containsValue(Object): This method is available in java.util.HashMap class of Java.
Syntax:
boolean java.util.HashMap.containsValue(Object value)
This method takes one argument. This method returns true if this map maps one or more keys to the specified value.
Parameters: One parameter is required for this method.
value: value whose presence in this map is to be tested.
Returns: true if this map maps one or more keys to the specified value.
Exceptions: NA
Approach
Java
import java.util.HashMap;public class HashMapcontainsValue {public static void main(String[] args) {HashMap<String, Integer> hashMap =new HashMap<String, Integer>();hashMap.put("Hello", 1);hashMap.put("World", 2);Integer value = 1;System.out.println(hashMap.containsValue(value));}}
Output:
true
No comments:
Post a Comment