第一种方法:
一、定义枚举类
首选编写枚举类型值
定义变量
构造方法
编写枚举类的内部静态方法
public enum TestEstateTypeEnum { PAYMENT_BUSSINESS("PAYMENT_BUSSINESS","商业按揭购房"), PAYMENT_FUND("PAYMENT_FUND","公积金按揭购房"), PAYMENT_BUS_FUND("PAYMENT_BUS_FUND","商业&公积金组合按揭购房"), PAYMENT_NONE("PAYMENT_NONE","无按揭购房"), MORTGAGE_OWN("MORTGAGE_OWN","持证抵押房"), SELF_HELPING("SELF_HELPING","自建房"), ; public String text; public String testStr; TestEstateTypeEnum(String text, String testStr) { this.text = text; this.testStr = testStr; } public static TestEstateTypeEnum randomType(TestEstateTypeEnum[] values){ return values[(int)(Math.random()*values.length)]; } }