Java EnumMap keySet() method
Last Updated : 17 Mar 2025
The keySet() method of Java EnumMap class is used to get the set view of the keys contained in the map. This method returns a set of the keys in the natural order (the order in which the enum constants are declared).
Syntax
Parameters
NA
Returns
This method returns a set view of the keys contained in the enum map.
Exception
NA
Example 1
Output:
Map: {CSS=1, Python=2, PHP=3, Java=4}
KeySet: [CSS, Python, PHP, Java]
Example 2
Output:
Map: {Monday=1, Tuesday=2, Wednesday=3}
KeySet: [Monday, Tuesday, Wednesday]
Example 3
Output:
Map: {January=1, February=2, March=3, April=4}
KeySet: [January, February, March, April]