public enum Colar {
RED("红色", 1), GREEN("绿色", 2), BLANK("白色", 3), YELLO("黄色", 4);
private Stringname ;
private int index ;
private Colar( String name, int index ){
this.name = name;
this.index = 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;
}
}
class B {
public static void main(String[] args) {
//输出某一枚举的值
System.out.println( Colar.RED.getName() );
System.out.println( Colar.RED.getIndex() );
//遍历所有的枚举
for( Colar color : Colar.values()){
System.out.println( color +" name: " + color.getName() +" index: " + color.getIndex() );
}
}
}
个人公号:【排骨肉段】,可以关注一下。