EnumMap get() Method in Java
The Java.util.EnumMap.get(Object key) method in Java is used to give the mapped value of the specified key.
Syntax:
get(Object key)
Parameter: The method takes one parameter key which is passed to return the value associated with it.
Return Value: It returns the value mapped with the associated key.
Below programs illustrate the working of get() function:
Program 1:
// Java program to demonstrate get(key) import java.util.*; // An enum of geeksforgeeks public enum gfg { Global, India } ; class Enum_demo { public static void main(String[] args) { EnumMap<gfg, Integer> mp = new EnumMap<gfg, Integer>(gfg. class ); // Values are associated mp.put(gfg.Global, 800 ); mp.put(gfg.India, 72 ); // Stores the value mapped with the key specified int res = mp.get(gfg.India); // Prints the result System.out.println( "GeeksforGeeks ranked in India: " + res); } } |
chevron_right
filter_none
Output:
GeeksforGeeks ranked in India: 72
Program 2:
// Java program to demonstrate get(key) import java.util.*; // An enum of geeksforgeeks public enum gfg { India, United_States, China } ; class Enum_demo { public static void main(String[] args) { EnumMap<gfg, String> mp = new EnumMap<gfg, String>(gfg. class ); // Values are associated mp.put(gfg.India, "61.7%" ); mp.put(gfg.United_States, "18.2%" ); mp.put(gfg.China, "2.5%" ); // Stores the value mapped with the key specified String res = mp.get(gfg.United_States); // Prints the result System.out.println( "Visitors in United_States: " + res); } } |
chevron_right
filter_none
Output:
Visitors in United_States: 18.2%
Recommended Posts:
- EnumMap put() Method in Java
- EnumMap entrySet() Method in Java
- EnumMap containsKey() Method in Java
- EnumMap clone() Method in Java
- EnumMap containsValue(value) method in Java
- EnumMap putAll(map) Method in Java
- EnumMap remove() Method in Java
- EnumMap size() Method in Java
- EnumMap keySet() Method in Java
- EnumMap values() Method in Java
- EnumMap clear() Method in Java with Examples
- EnumMap equals() Method in Java with Examples
- EnumMap class in Java
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.