How to store value of enum in arraylist?
You could build that list inside the enum
itself like this:
public enum SomeEnum { ENUM_VALUE1("Some value1"), ENUM_VALUE2("Some value2"), ENUM_VALUE3("Some value3"); private static final List<String> VALUES; private final String value; static { VALUES = new ArrayList<>(); for (SomeEnum someEnum : SomeEnum.values()) { VALUES.add(someEnum.value); } } private SomeEnum(String value) { this.value = value; } public static List<String> getValues() { return Collections.unmodifiableList(VALUES); }}
Then you can access this list with:
List<String> values = SomeEnum.getValues();