Say I have an enum which that is:
public enum FooBar {
One, Two, Three
}
I would like to get the corresponsing enum value of a string, lets say ‘Two’, and get FooBar.Two.
How can I do this in Java? Enum.ValueOf() does not seem to be related.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To do this you use
valueOfe.g.or
It appears it’s exactly what you want.
You can use either
or
You can use
toString()to turn any object in to a String. (Whether that String makes sense of not depends on the implementation 😉