Package com.ibm.enums;
public class Testenum {public enum colorenums{red, green, yellow,blue;
public enum male{Formale ("Girl", 1), Male ("Boy", 2);
private String name;
private int index;
Public String GetName () {return name;
public void SetName (String name) {this.name = name;
public int GetIndex () {return index;
public void Setindex (int index) {this.index = index;
////Construct method Private Male (String Name,int index) {this.name = name;
This.index = index; } public static void Main (string[] args) {//TODO auto-generated Method Stub//Traversal enumeration for (Colorenums CE:C
Olorenums.values ()) {//The values here are the variables themselves System.out.println (CE);
The value in the enumeration is obtained by "enumeration name. Value" when assigned colorenums a = Colorenums.green;
Switch (a) {case red:System.out.println (' is red ');
Break
Case Green:System.out.println ("It is green");
Break Case Yellow:System.out.println (' This is yellow ");
Break
///computes the number of enumerations System.out.println ("Colorenums Enumerator:" + colorenums.values (). length); Evaluates the index System.out.println (ColorEnums.blue.ordinal ()) of the enumeration; The Compare Method System.out.println (ColorEnums.blue.co) is implemented in the Blue location is 3, the It looks like Bigan from 0//enumeration method Mpareto (Colorenums.green)); 2//More complex enumeration Male for (Male m:male.values ()) {System.out.println (M.index + ":" + m.name);
M.values () is an object System.out.println ();
}
}
}
Red
Green
Yellow
Blue
This is green
Colorenums Number of enumerations: 4
3
2
1:girl
2
2:boy
2