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
  • 343
  • 2
  • 12

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
  • 263,859
  • 56
  • 671
  • 702
zThulj
  • 149
  • 7