Java Class.getEnumConstants()

Syntax

Class.getEnumConstants() has the following syntax.

public T [] getEnumConstants()

Example

In the following code shows how to use Class.getEnumConstants() method.


//from  w  w w . j ava 2  s  .  c  om
enum Programming {
  java, python,
}

public class Main {

  public static void main(String[] args) {
    Class cls = Programming.class;

    // returns the elements of this enum class
    for (Object obj : cls.getEnumConstants()) {
      System.out.println(obj);
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable