Alf Alf - 1 year ago 120
Java Question

List of enum values in java

Is it possible to create ArrayList of enum values (and manipulate it)? For example:

enum MyEnum

MyEnum my = MyEnum.ONE;
List <?> al = new ArrayList <?>();

Answer Source

Yes it is definitely possible, but you will have to do

List<MyEnum> al = new ArrayList<MyEnum>();

You can then add elements to al: al.add(ONE) or al.add(TWO).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download