Java Enum.name()
Syntax
Enum.name() has the following syntax.
public final String name()
Example
In the following code shows how to use Enum.name() method.
/*from ww w . j a v a 2s . co m*/
enum Tutorial {
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[]) {
System.out.println("CellPhone List:");
for(Tutorial m : Tutorial.values()) {
System.out.println(m + " costs " + m.showPrice() + " dollars");
}
Tutorial ret = Tutorial.Java;
System.out.println("TutorialName = " + ret.name());
}
}
The code above generates the following result.