Saturday, June 13, 2026
HomeLanguagesJavaEnumMap containsValue(value) method in Java

EnumMap containsValue(value) method in Java

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 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 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
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS