Java 枚举学习
1. 新建一个枚举类型
public enum ColorForUsing
{
RED("红色",0),
GREEN("绿色",1),
BLUE("蓝色",2),
ORENGE("橙色",3);
private String name;
private int index;
private ColorForUsing(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;
}
@Override
public String toString() {
// TODO Auto-generated method stub
StringBuilder str = new StringBuilder(this.getName()).append("-->").append(this.getIndex());
return str.toString();
}
}
2. 测试一下用法
public class Process {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(ColorForUsing.BLUE.toString());
}
}
3.到这里相信聪明的你已经完全懂了