EnumMap containsValue(value) method in Java
Last Updated :
24 Jul, 2020
The Java.util.EnumMap.containsValue(
value) method in Java is used to determine whether one or more key of the map is associated with a given value or not. It takes the value as a parameter and returns True if that value is mapped by any of the keys in the EnumMap.
Syntax:
boolean containsValue(Object value)
Parameter: The method accepts one parameter
value which refers to the value whose mapping is to be checked by any of the key.
Return Value: It returns true when one or more key is mapped to same value.
Below programs illustrate the containsValue() method:
Program 1:
Java
// Java program to demonstrate containsValue() method
import java.util.*;
// An enum of gfg ranking is created
public enum rank_countries {
India,
United_States,
China,
Japan,
Canada,
Russia
};
class Enum_map {
public static void main(String[] args)
{
EnumMap<rank_countries, Integer> mp = new
EnumMap<rank_countries,Integer>(rank_countries.class);
// values are associated in mp
mp.put(rank_countries.India, 72);
mp.put(rank_countries.United_States, 1083);
mp.put(rank_countries.China, 4632);
mp.put(rank_countries.Japan, 6797);
mp.put(rank_countries.Canada, 1820);
// check if map contains mapping at specified key
boolean ans = mp.containsValue(72);
// prints the result
System.out.println("Map contains 72: " + ans);
}
}
Output:
Map contains 72: true
Program 2:
Java
// Java program to demonstrate containsValue() method
import java.util.*;
// An enum of gfg ranking is created
public enum rank_countries {
India,
United_States,
China,
Japan,
Canada,
Russia
};
class Enum_map {
public static void main(String[] args)
{
EnumMap<rank_countries, Integer> mp = new
EnumMap<rank_countries,Integer>(rank_countries.class);
// values are associated in mp
mp.put(rank_countries.India, 72);
mp.put(rank_countries.United_States, 1083);
mp.put(rank_countries.China, 4632);
mp.put(rank_countries.Japan, 6797);
mp.put(rank_countries.Canada, 1820);
// check if map contains mapping at specified key
boolean ans = mp.containsValue(2000);
// prints the result
System.out.println("Map contains 2000: " + ans);
}
}
Output:
Map contains 2000: false