EnumMap get() Method in Java
Last Updated :
13 Jul, 2018
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:
import java.util.*;
public enum gfg {
Global,
India
}
;
class Enum_demo {
public static void main(String[] args)
{
EnumMap<gfg, Integer> mp = new
EnumMap<gfg, Integer>(gfg. class );
mp.put(gfg.Global, 800 );
mp.put(gfg.India, 72 );
int res = mp.get(gfg.India);
System.out.println( "GeeksforGeeks ranked in India: "
+ res);
}
}
|
Output:
GeeksforGeeks ranked in India: 72
Program 2:
import java.util.*;
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 );
mp.put(gfg.India, "61.7%" );
mp.put(gfg.United_States, "18.2%" );
mp.put(gfg.China, "2.5%" );
String res = mp.get(gfg.United_States);
System.out.println( "Visitors in United_States: "
+ res);
}
}
|
Output:
Visitors in United_States: 18.2%
Share your thoughts in the comments
Please Login to comment...