0

I have enum class like this:

REGULARLY("Regularly"),
SOCIALLY("Socially"),
RARELY("Rarely"),
NEVER("Never");

private  final String name;

Drink(String s) {
    name = s;
}

How to get value of enum field by its position. For example for position 0 output should be "Regularly". NOT THE "REGULARLY"

Evgeniy Rechkov
  • 465
  • 4
  • 15

1 Answers1

1

To get them in order, you can use Drink.values().

Then, you should rename your name field to something else, and create a getter for it. (Or keep this name and create a getName() getter, but do not use name().)

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
zThulj
  • 149
  • 7