get(Object): This method is available in java.util.EnumMap class of Java.
Syntax:
V java.util.EnumMap.get(Object key)
This method takes one argument of type Object as its parameter. This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
Parameters: One parameter is required for this method.
key: the key whose associated value is to be returned.
Returns: the value to which the specified key is mapped, or null if this map contains no mapping for the key.
Exceptions: NA
Approach
Java
import java.util.EnumMap;public class EnumMapget {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.get(Colour.RED));}}
Output:
Red
No comments:
Post a Comment