containsValue(Object): This method is available in java.util.EnumMap class of Java.
Syntax:
boolean java.util.EnumMap.containsValue(Object value)
This method takes one argument of type Object as its parameter. 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: the value whose presence in this map is to be tested.
Returns: true if this map maps one or more keys to this value.
Exceptions: NA
Approach
Java
import java.util.EnumMap;public class EnumMapcontainsValue {public enum Colour {RED, GREEN, YELLOW, ORANGE};public static void main(String[] args) {EnumMap<Colour, String> enumMap =new EnumMap<Colour, String>(Colour.class);enumMap.put(Colour.RED, "Red");enumMap.put(Colour.GREEN, "Green");enumMap.put(Colour.YELLOW, "Yellow");enumMap.put(Colour.ORANGE, "Orange");System.out.println(enumMap.containsValue("Red"));}}
Output:
true
No comments:
Post a Comment