1

Here's the code :

enum Status {

    STATUS_OPEN(10),
    STATUS_STARTED(11),
    STATUS_INPROGRESS(12);

    private final int status;

    Status(int aStatus) {
        this.status = aStatus;
    }

    public int getStatus() {
        return this.status;
    }

}

class StatusTest3 {

    public static void main(String[] args) {

        for (Status stat : Status.values()) {
            System.out.println(stat + " value is " + stat.getStatus());
        }
    }
}

What does Status.values() return ?

and the output is :

STATUS_OPEN value is 10
STATUS_STARTED value is 11
STATUS_INPROGRESS value is 12
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Ajinkya
  • 147
  • 1
  • 2
  • 11

2 Answers2

1

http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html

All the constants of an enum type can be obtained by calling the implicit public static T[] values() method of that type.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

Status.values() : will return an array containing the constants of this enum type, in the order they're declared

Read JLS for more: http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9.2

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136