Enum: valueOf(String v) : Enum « java.lang « Java by API






Enum: valueOf(String v)

/*
Here are all Apple constants
A
B
C
D
E

ap contains C
 */
enum Apple {  
  A, B, C, D, E 
} 
 
public class MainClass { 
  public static void main(String args[])  
  { 
    Apple ap; 
 
    System.out.println("Here are all Apple constants"); 

    Apple allapples[] = Apple.values(); 
    for(Apple a : allapples) 
      System.out.println(a); 
 
    System.out.println(); 
    
    ap = Apple.valueOf("C"); 
    System.out.println("ap contains " + ap); 
 
  } 
}

           
       








Related examples in the same category

1.Enum: compareTo(Object o)
2.Enum: equals(Object other)
3.Enum: name()
4.Enum: ordinal()
5.Enum: values()