爪哇。util。地图。得到( 对象键 )方法用于给出指定键的映射值。
null
语法:
get(Object key)
参数: 该方法采用一个参数 钥匙 它被传递以返回与之关联的值。
返回值: 它返回与相关键映射的值。
下面的程序说明了get()函数的工作原理:
项目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); } } |
输出:
GeeksforGeeks ranked in India: 72
项目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); } } |
输出:
Visitors in United_States: 18.2%
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END