Enum.valueOf(Class <T> enumType, String name) has the following syntax.
public static <T extends Enum <T>> T valueOf(Class <T> enumType, String name)
In the following code shows how to use Enum.valueOf(Class <T> enumType, String name) method.
enum Tutorial {/*from w ww . j a v a2 s .co m*/ CSS(400), HTML(250),Java(325); int price; Tutorial(int p) { price = p; } int showPrice() { return price; } } public class Main { public static void main(String args[]) { for(Tutorial m : Tutorial.values()) { System.out.println(m + " costs " + m.showPrice() + " dollars"); } Tutorial ret; ret = Tutorial.valueOf("CSS"); System.out.println("Selected : " + ret); } }
The code above generates the following result.