Efficiently converting java string to its equivalent enum
Given a string i want to get the enum equivalent of it in constant time. I have a enum defined like the one shown in the question. Best way to create enum of strings? public enum Strings { STRING_ONE("ONE"), STRING_TWO("TWO") ; private final String text; /** * @param text */ private Strings(final String text) { this.text = text; } /* (non-Javadoc) * @see java.lang.Enum#toString() */ @Override public String toString() { return text; } } If i now get a string (say "TWO"), is there a way to see if it exists and if it exists then is there a way i can define a method that will return the enum value