5624/java-enum-lookup-using-a-string
I need to find the enum value of String, suppose “Y” that should be Test.Y.
My enum looks like below:
public enum Test { W, X, Y, Z }
Should I use Enum.valueOf() or something else?
Yes, you are going on the right path. Using Test.valueOf(“Y”) will return Test.Y.
Just remember this, the valueOf() is case-sensitive and will throw an IllegalArgumentException. So, when you are passing the arguments, be careful regarding the values.
Check this...Java Enum in details
public static byte[] hexStringToByteArray(String s) { ...READ MORE
Hello @kartik, Yes, Blah.valueOf("A") will give you Blah.A. Note that the name ...READ MORE
If you're simply outputting text, rather than ...READ MORE
Here are two ways illustrating this: Integer x ...READ MORE
We can use Apache Commons IO. It ...READ MORE
try { final Path ...READ MORE
Yes; the Java Language Specification writes: In the Java ...READ MORE
You can use split() method. str = "Hello ...READ MORE
java.time Package The new java.time.package in Java 8 incorporates ...READ MORE
Yes, you are missing out on a ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.