Http://www.cnblogs.com/wenruo/p/5349614.html
The enumeration of Java is implemented by the keyword enum. Can be understood as a class, but this class is automatically added by the compiler to some methods.
The static values () method is used to produce an array of these constant values in the order in which the enum constants are declared
Ordinal indicates the order of declarations for a particular enum constant
ToString () to display the name of each enum instance
Can be used in a switch statement, but note that the case is directly written with constants, without the name of enum.
1 enumspiciness {2 //expressed in uppercase letters3Not, MILD, MEDIUM, hot, flaming,//<--here comma dispensable4 };5 6 Public classEnumdemo {7 Public Static voidMain (string[] args) {8 //Range for9 for(spiciness s:spiciness.values ()) {TenSYSTEM.OUT.PRINTLN (S + ", ordinal" +s.ordinal ()); One } A -spiciness[] sp =NewSpiciness[2]; -Sp[0] =spiciness.flaming; theSP[1] =Spiciness.medium; - - Switch(sp[0]) { - CaseNOT:System.out.println ("not spicy @ all"); + Break; - CaseMILD://Note not spiciness. MILD + CaseMEDIUM:System.out.println ("A Little not"); A Break; at CaseHot : - CaseFlaming: - default: System.out.println ("Maybe Too hot"); - } - } -}
Java enum enum