Here’s my problem – I’m looking for (if it even exists) the enum equivalent of ArrayList.contains();.

Here’s a sample of my code problem:

enum choices {a1, a2, b1, b2};

if(choices.???(a1)}{
//do this
} 

Now, I realize that an ArrayList of Strings would be the better route here but I have to run my enum contents through a switch/case elsewhere. Hence my problem.

Assuming something like this doesn’t exist, how could I go about doing it?

32 Answers
32

Use the Apache commons lang3 lib instead

 EnumUtils.isValidEnum(MyEnum.class, myValue)

Leave a Reply

Your email address will not be published. Required fields are marked *