-2
我正在寻找一种方法来搜索一个枚举,以查看用户提供的字符串是否与任何值匹配,所以我创建了这个。这是否被认为是一种很好的搜索方法一个枚举?是这样搜索一个枚举可接受的
enum Month {JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC};
try {
String A = "DECc";
Month.valueOf(A);
} catch(Exception e) {
System.out.println("Could not find an enum with the String you entered");
}
那么,你的问题是什么? – YakovL