Java中根据枚举索引值获取枚举值

Java中根据枚举索引值获取枚举值,还是很简单的。我们主要用 class 下的
getEnumConstants 来实现

enum SexEnum{
 	MALE,FEMALE
}

public static void main(String[] args) throws SQLException {   
  System.out.println(SexEnum.class.getEnumConstants()[1]); // FEMALE 默认从0开始
}
# Java 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×