Open In App

Class getEnumConstants() method in Java with Examples

Last Updated : 27 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The getEnumConstants() method of java.lang.Class class is used to get the Enum constants of this class. The method returns the Enum constants of this class in the form of an array of objects comprising the enum class represented by this class. Syntax:
public T[] getEnumConstants()
Parameter: This method does not accepts any parameter Return Value: This method returns the specified Enum constants of this class in the form of an array of Enum objects. Below programs demonstrate the getEnumConstants() method. Example 1:
Output:
Class represented by myClass: class A
Enum constants of myClass: []
Example 2:
Output:
Class represented by myClass: class A
Enum constants of myClass: [RED, GREEN, BLUE]
Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#getEnumConstants--

Next Article
Practice Tags :

Similar Reads