Java enums from a given string
This post is part of the archive. It was written years ago, so some of the tools, versions and links may be outdated.
To generate a instance of a enum class by a given string you can use the valueOf() method.
public class EnumByGivenStringSample {
private enum Language
{
JAVA, RUBY, SCALA, GROOVY, CLOJURE
}
public static Language languageByString(String language)
{
return Language.valueOf(language);
}
}