Enum: ordinal() : Enum « java.lang « Java by API






Enum: ordinal()

/*
A 0
B 1
C 2
D 3
E 4

 */
enum Apple {  
  A, B, C, D, E 
} 
 
public class MainClass { 
  public static void main(String args[])  
  { 

    for(Apple a : Apple.values()) 
      System.out.println(a + " " + a.ordinal()); 
 
  } 
}

           
       








Related examples in the same category

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