枚举类型的使用 我现在有个枚举的使用场景,请问各位大虾怎么处理1.有个枚举类型public enum SystemType{windows(0);linux(1);}某段程序能得到0,如何能取到对应的SystemType.windows枚举类 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你想问,比如根据0获取 window? for (SystemType type : SystemType.values()) { if (type.ordinal() == 0) { System.out.println(type); break; } } SystemType[] s = SystemType.values(); for(SystemType s1:s) { if(s1.ordinal()== a) { SystemType target = s1; } }遍历下可以得到 public class TestAdd { public enum OS{ linux(0), window(1); private final int value; private OS(int a){ this.value = a; } } public static void main(String[] args) { for (OS prop : OS.values()){ if(prop.value == 0){ System.out.println(prop); } } }} 你可以在SystemType里面加一个方法:SystemType getSystemTypeFromInt(int i){ for (SystemType st : values()) { if (st.ordinal() == i) return st; } //无法转换 return null;}这样勉强能达到你要的效果 1. for(SystemType myType: SystemType.values()){ if(myType.ordinal() == 0){ return myType; } }2. if(type.ordinal() == 0){ return SystemType.windows; } container相关理解 这段话看不懂,请解释 关于JAVA调用存储过程的问题,急急。。。 下载java源代码的好地方 如何访问Jar文件中的文件? 如何写这个正则表达式:判断一个字符串为数字字符串 JSwing能否支持中文? 两套mis系统,一套用B/S结构,一套用C/S结构,两者业务完全相同,在对客户介绍时如何突出B/S系统优点?应从那几个方面说明 奇怪的问题!!!个位大虾帮忙!!!! 各位,救急呀!怎样将ResultSet中的数据逐行放入Vector对象中?? 关于Math.random,这种写法是什么意思? JSplitPane的一个问题
if (type.ordinal() == 0) {
System.out.println(type);
break;
}
}
for(SystemType s1:s)
{
if(s1.ordinal()== a)
{
SystemType target = s1;
}
}
遍历下可以得到
public enum OS{
linux(0),
window(1);
private final int value;
private OS(int a){
this.value = a;
}
}
public static void main(String[] args) {
for (OS prop : OS.values()){
if(prop.value == 0){
System.out.println(prop);
}
}
}}
{
for (SystemType st : values())
{
if (st.ordinal() == i)
return st;
}
//无法转换
return null;
}这样勉强能达到你要的效果
if(myType.ordinal() == 0){
return myType;
}
}2. if(type.ordinal() == 0){
return SystemType.windows;
}