Enum.name() has the following syntax.
public final String name()
In the following code shows how to use Enum.name() method.
// w w w .ja va 2 s.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.