Java Enum.valueOf(Class <T> enumType, String name)
Syntax
Enum.valueOf(Class <T> enumType, String name) has the following syntax.
public static <T extends Enum <T>> T valueOf(Class <T> enumType, String name)
Example
In the following code shows how to use Enum.valueOf(Class <T> enumType, String name) method.
enum Tutorial {// w w w. j a v a 2s . 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.