我有一个 Java 枚举:
public enum Months
{
JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
}
我想通过索引访问枚举值,例如
Months(1) = JAN;
Months(2) = FEB;
...
我该怎么做?
最佳答案
试试这个
Months.values()[index]
关于java - 如何从 Java 中的索引中获取枚举值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6692664/