EnumMap keySet() Method in Java
The Java.util.EnumMap.keySet() method in Java is used to return the set view of the keys contained in the map.
Syntax:
Enum_Map.keySet()
Parameters: The method does not accept any argument.
Return Value: The method returns the set view of the keys contained in the map.
Below programs illustrate the keySet() function:
Program 1:
// Java program to demonstrate keySet() 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%"); // Prints the map System.out.println("Mappings: " + mp); // Store the set view of the key Set<gfg> set_view = mp.keySet(); // Print the result System.out.println("Set view of the key: " + set_view); } } |
chevron_right
filter_none
Output:
Mappings: {India=61.7%, United_States=18.2%, China=2.5%}
Set view of the key: [India, United_States, China]
Program 2:
// Java program to demonstrate keySet() import java.util.*; // An enum of geeksforgeeks public enum gfg { Global_today, India_today }; 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_today, 799); mp.put(gfg.India_today, 69); // Prints the map System.out.println("Mappings: " + mp); // Store the set view of the key Set<gfg> set_view = mp.keySet(); // Print the result System.out.println("Set view of the key: " + set_view); } } |
chevron_right
filter_none
Output:
Mappings: {Global_today=799, India_today=69}
Set view of the key: [Global_today, India_today]
Recommended Posts:
- Map keySet() Method in Java with Examples
- IdentityHashMap keySet() Method in Java
- HashMap keySet() Method in Java
- TreeMap keySet() Method in Java
- WeakHashMap keySet() method in Java
- EnumMap put() Method in Java
- EnumMap get() Method in Java
- AbstractMap keySet() Method in Java with Examples
- SortedMap keySet() method in Java with Examples
- Provider keySet() method in Java with Examples
- ConcurrentHashMap keySet() method in Java with Examples
- Properties keySet() method in Java with Examples
- EnumMap entrySet() Method in Java
- EnumMap putAll(map) Method in Java
- EnumMap containsValue(value) method in Java
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.



