Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.5k
  • 22
  • 110
  • 134

How to get an enum value from a string value in Java?

How to get an enum value from a string value in Java?

Say I have an enum which is just

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. How would it be possible to do this?

Is the Enum.valueOf() the method I need? If so, how would I use this?

How to get an enum value from a string value in Java?

Say I have an enum which is just

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. How would it be possible to do this?

Is the Enum.valueOf() the method I need? If so, how would I use this?

How to get an enum value from a string value in Java

Say I have an enum which is just

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. How would it be possible to do this?

Is the Enum.valueOf() the method I need? If so, how would I use this?

added 138 characters in body
Source Link
Basil Bourque
  • 346k
  • 128
  • 949
  • 1.3k

Say I have an enum which is just

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. How would it be possible to do this?

Is the Enum.valueOf()Enum.valueOf() the method I need? If so, how would I use this?

Say I have an enum which is just

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. How would it be possible to do this?

Is the Enum.valueOf() the method I need? If so, how would I use this?

Say I have an enum which is just

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. How would it be possible to do this?

Is the Enum.valueOf() the method I need? If so, how would I use this?

Improved title
Link
Steve Chambers
  • 39.7k
  • 29
  • 178
  • 222

Lookup Java How to get an enum byvalue from a string value in Java?

I know it's tagged Java but I found it via Google and was puzzled why it didn't solve my C# problem!
Link
Andy Baker
  • 21.6k
  • 12
  • 60
  • 71
Loading
edited title
Link
Sotirios Delimanolis
  • 280.9k
  • 62
  • 718
  • 744
Loading
added 1 character in body; edited title
Source Link
Radiodef
  • 38k
  • 14
  • 95
  • 127
Loading
edited tags
Link
ThiefMaster
  • 319.8k
  • 85
  • 607
  • 648
Loading
Question Protected by hsz
Loading
Rollback to Revision 4
Link
Moog
  • 10.2k
  • 2
  • 42
  • 68
Loading
Removed extraneous tags
Link
Moog
  • 10.2k
  • 2
  • 42
  • 68
Loading
Removed meta information.
Source Link
Peter Mortensen
  • 31.5k
  • 22
  • 110
  • 134
Loading
formatting, spelling correction
Source Link
cletus
  • 626.8k
  • 169
  • 922
  • 945
Loading
added 48 characters in body; edited title
Source Link
sblundy
  • 61.5k
  • 22
  • 124
  • 124
Loading
Source Link
Malachi
  • 33.9k
  • 18
  • 67
  • 96
Loading