I am reading from and xml file configuration file. The data being returned is stored as a String and corresponds to a Enum value. My question is - What is the best way to assign the enum the value that corresponds to value of the string?
public enum Names { BOB, FRED, JIM, SAM }
String name = "FRED"; // This is the data retuned from the xml file.
Names n = // I want to assign n the value of Names.FRED
I know I could do an "if" statement. However, this is a contrived example with only a few enum values. In the real world, this enum list could be quite large.
I have looked into reflection, but I don't know whether there is an easier way to achieve my objective?
Thank you for your time,
Harold Clements