Class getEnumConstants() method in Java with Examples Last Updated : 12 Jul, 2025 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: Java // Java program to demonstrate // getEnumConstants() method import java.util.*; enum A {} public class Test { public Object obj; public static void main(String[] args) { // returns the Class object for this class Class myClass = A.class; System.out.println("Class represented by myClass: " + myClass.toString()); // Get the Enum constants of myClass // using getEnumConstants() method System.out.println( "Enum constants of myClass: " + Arrays.toString( myClass.getEnumConstants())); } } Output: Class represented by myClass: class A Enum constants of myClass: [] Example 2: Java // Java program to demonstrate // getEnumConstants() method import java.util.*; enum A { RED, GREEN, BLUE; } class Main { private Object obj; public static void main(String[] args) { try { // returns the Class object for this class Class myClass = A.class; System.out.println("Class represented by myClass: " + myClass.toString()); // Get the Enum constants of myClass // using getEnumConstants() method System.out.println( "Enum constants of myClass: " + Arrays.toString( myClass.getEnumConstants())); } catch (Exception e) { System.out.println(e); } } } 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-- Comment More infoAdvertise with us Next Article Class getConstructors() method in Java with Examples S srinam Follow Improve Article Tags : Java Java-lang package Java-Functions Java.lang.Class Practice Tags : Java Similar Reads Class getConstructors() method in Java with Examples The getConstructors() method of java.lang.Class class is used to get the constructors of this class, which are the constructors that are public. The method returns the constructors of this class in the form of array of Constructor objects. Syntax: public Constructor[] getConstructors() Parameter: Th 2 min read Class getConstructors() method in Java with Examples The getConstructors() method of java.lang.Class class is used to get the constructors of this class, which are the constructors that are public. The method returns the constructors of this class in the form of array of Constructor objects. Syntax: public Constructor[] getConstructors() Parameter: Th 2 min read Class getConstructors() method in Java with Examples The getConstructors() method of java.lang.Class class is used to get the constructors of this class, which are the constructors that are public. The method returns the constructors of this class in the form of array of Constructor objects. Syntax: public Constructor[] getConstructors() Parameter: Th 2 min read Class getConstructor() method in Java with Examples The getConstructor() method of java.lang.Class class is used to get the specified constructor of this class with the specified parameter type, which is the constructor that is public and its members. The method returns the specified constructor of this class in the form of Constructor object. Syntax 2 min read Class getConstructor() method in Java with Examples The getConstructor() method of java.lang.Class class is used to get the specified constructor of this class with the specified parameter type, which is the constructor that is public and its members. The method returns the specified constructor of this class in the form of Constructor object. Syntax 2 min read Class getConstructor() method in Java with Examples The getConstructor() method of java.lang.Class class is used to get the specified constructor of this class with the specified parameter type, which is the constructor that is public and its members. The method returns the specified constructor of this class in the form of Constructor object. Syntax 2 min read Like