Alf Alf - 11 days ago 5
Java Question

List of enum values in java

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

enum MyEnum
{
ONE, TWO
}

MyEnum my = MyEnum.ONE;
List <?> al = new ArrayList <?>();
al.add(my);
al.remove(al.size()-1);

Answer

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).

Comments