如何從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
相關文章
相關標籤/搜索