The valueOf( ) method returns the enumeration constant whose value corresponds to the string passed in str
Example of valuesof() method
An enumeration of apple varieties
enum Apple {
Jonathan, GoldenDel, RedDel, Winesap, Cortland
}
class EnumDemo2 {
public static void main(String args[])
{
Apple ap;
System.out.println(“Here are all Apple constants:”);
// use valueOf()
ap = Apple.valueOf(“Winesap”);
System.out.println(“ap contains ” + ap);
}
}
Output of valueof() method
ap contains Winesap