List of enum values in java

后端 未结 6 1618
执笔经年
执笔经年 2021-02-01 00:59

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          


        
6条回答
  •  無奈伤痛
    2021-02-01 01:52

    It is possible but you should use EnumSet instead

    enum MyEnum {
        ONE, TWO;
        public static final EnumSet all = EnumSet.of(ONE, TWO);
    }
    

提交回复
热议问题