我有一个枚举:
public enum Platform {
Xbox360, XboxOne, Playstation3,
Playstation4, PC
}我想迭代并打印它的所有常量。我怎么才能得到尺码?或者为此目的,我不应该使用枚举,而应该使用数组?
发布于 2016-02-21 13:22:00
您只需使用<EnumName>.values()获取枚举常量数组即可。
Platform[] platforms = Platform.values();您可以使用该数组获取元素的数量/遍历元素。
发布于 2016-02-21 13:22:24
int size = Platform.values().length;或者迭代它们:
for (Platform platform : Platform.values()) {
// code here
}发布于 2016-02-21 13:22:28
要迭代,可以执行以下操作:
for(Platform platform : Platform.values()){
//your code
}https://stackoverflow.com/questions/35536629
复制相似问题