Java: Check if enum contains a given string?

后端 未结 29 1575
一个人的身影
一个人的身影 2020-12-02 03:59

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:

<         


        
29条回答
  •  佛祖请我去吃肉
    2020-12-02 04:42

    Java Streams provides elegant way to do that

    Stream.of(MyEnum.values()).anyMatch(v -> v.name().equals(strValue))
    

    Returns: true if any elements of the stream match the provided value, otherwise false

提交回复
热议问题