如何从Java中的字符串值获取枚举值? - How to get an enum value from a string value in Java?

问题:

Say I have an enum which is just 说我有一个枚举 this

public enum Blah {
    A, B, C, D
}

and I would like to find the enum value of a string, for example "A" which would be Blah.A . 我想找到一个字符串的枚举值,例如"A"就是Blah.A How would it be possible to do this? 怎么可能作到这一点? spa

Is the Enum.valueOf() the method I need? Enum.valueOf()是我须要的方法吗? If so, how would I use this? 若是是这样,我将如何使用它? .net


解决方案:

参考一: https://stackoom.com/question/2XEm/如何从Java中的字符串值获取枚举值
参考二: https://oldbug.net/q/2XEm/How-to-get-an-enum-value-from-a-string-value-in-Java
相关文章
相关标签/搜索