Java中的Java.util.EnumMap.entrySet()方法用於創建EnumMap中包含的元素的集合。它本質上返回枚舉映射的設置視圖。
用法:
enum_map.entrySet()
參數:該方法不帶任何參數。
返回值:該方法返回此enum_map中包含的映射的設置視圖。
以下示例程序旨在說明entrySet()方法:
示例1:
// Java program to demonsrate entrySet() method
import java.util.*;
// An enum of gfg rank is created
public enum rank_countries {
India,
United_States,
China,
Japan,
Canada,
Russia
}
;
class Enum_map {
public static void main(String[] args)
{
EnumMap<rank_countries, Integer> mp = new
EnumMap<rank_countries, Integer>(rank_countries.class);
// Values are associated in mp
mp.put(rank_countries.India, 72);
mp.put(rank_countries.United_States, 1083);
mp.put(rank_countries.China, 4632);
mp.put(rank_countries.Japan, 6797);
// Map view
System.out.println("Map view: " + mp);
// Creating a new set of the mappings
// contained in map
Set<Map.Entry<rank_countries, Integer> > set_view =
mp.entrySet();
// Set view of the mappings
System.out.println("Set view of the map: " + set_view);
}
}
輸出:
Map view: {India=72, United_States=1083, China=4632, Japan=6797} Set view of the map: [India=72, United_States=1083, China=4632, Japan=6797]
示例2:
// Java program to demonsrate entrySet() method
import java.util.*;
// An enum of gfg ranking worldwide and in india
public enum gfg {
Global_2018,
India_2018
};
class Enum_map {
public static void main(String[] args)
{
EnumMap<gfg, Integer> mp = new
EnumMap<gfg, Integer>(gfg.class);
// Values are associated in mp
mp.put(gfg.Global_2018, 800);
mp.put(gfg.India_2018, 72);
// Mapping view
System.out.println("Mapping view: " + mp);
// Creating a new set of the mappings
Set<Map.Entry<gfg, Integer> > set_view =
mp.entrySet();
// Set view of the mappings
System.out.println("Set view of the map: "
+ set_view);
}
}
輸出:
Mapping view: {Global_2018=800, India_2018=72} Set view of the map: [Global_2018=800, India_2018=72]
相關用法
- Java WeakHashMap entrySet()用法及代碼示例
- Java TreeMap entrySet()用法及代碼示例
- Java HashMap entrySet()用法及代碼示例
- Java Map entrySet()用法及代碼示例
- Java IdentityHashMap entrySet()用法及代碼示例
- Java EnumMap put()用法及代碼示例
- Java EnumMap get()用法及代碼示例
- Java Provider entrySet()用法及代碼示例
- Java Properties entrySet()用法及代碼示例
- Java AbstractMap entrySet()用法及代碼示例
- Java SortedMap entrySet()用法及代碼示例
- Java ConcurrentHashMap entrySet()用法及代碼示例
- Java EnumMap values()用法及代碼示例
- Java EnumMap putAll(map)用法及代碼示例
- Java EnumMap clone()用法及代碼示例
注:本文由純淨天空篩選整理自akash1295大神的英文原創作品 EnumMap entrySet() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。