枚举使用
Posted lhl-shubiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了枚举使用相关的知识,希望对你有一定的参考价值。
package cn.com.cfets.imt.client;
public enum AnotherEnum {
/**
* enum 中的values()返回枚举数组 ; valueof():将普通意义上的字符串转换为枚举实例 orlinal()获取枚举成员的索引位置
*/
MEMBERBASICINFO("CG","竞价会员基础信息"),
CNYMARKETCLOSE("hY","结售汇市场闭市信息"),
G7MARKETCLOSE("hN","外币对市场闭市信息 "),
CNYBIDDINGDEAL("8Y","结售汇竞价成交明细"),
G7BIDDINGDEAL("8N","外币对竞价成交明细"),
CNYCENTRALPARITY("WD","中间价"),
CNYSETTLEMENT("BQY","结售汇市场结算清单"),
G7SETTLEMENT("BQN","外币对市场结算清单"),
VALUEDATE("WT", "起息日数据");
private String value;
private String discription;
private AnotherEnum(String value, String discription) {
this.value = value;
this.discription = discription;
}
public String getValue() {
return value;
}
public String getDiscription() {
return discription;
}
public static AnotherEnum getEnum(String value){
AnotherEnum anotherEnum = null;
AnotherEnum e[] = AnotherEnum.values();
for (int i = 0; i < e.length; i++) {
if(e[i].value.equals(value)){
anotherEnum = e[i];
break;
}
}
return anotherEnum;
}
public static void main(String[] args) {
System.out.println(AnotherEnum.getEnum("BQY").getDiscription()+";discription:"+AnotherEnum.getEnum("BQY").getValue());
}
// 二
public enum Opration{
OPRATION_SERVER_CHECK,
OPRATION_SERVER_DB,
OPRATION_SERVER_SEREVICES,
OPRATION_SERVER_PUSHTO_STREAM;
}
}
public enum AnotherEnum {
/**
* enum 中的values()返回枚举数组 ; valueof():将普通意义上的字符串转换为枚举实例 orlinal()获取枚举成员的索引位置
*/
MEMBERBASICINFO("CG","竞价会员基础信息"),
CNYMARKETCLOSE("hY","结售汇市场闭市信息"),
G7MARKETCLOSE("hN","外币对市场闭市信息 "),
CNYBIDDINGDEAL("8Y","结售汇竞价成交明细"),
G7BIDDINGDEAL("8N","外币对竞价成交明细"),
CNYCENTRALPARITY("WD","中间价"),
CNYSETTLEMENT("BQY","结售汇市场结算清单"),
G7SETTLEMENT("BQN","外币对市场结算清单"),
VALUEDATE("WT", "起息日数据");
private String value;
private String discription;
private AnotherEnum(String value, String discription) {
this.value = value;
this.discription = discription;
}
public String getValue() {
return value;
}
public String getDiscription() {
return discription;
}
public static AnotherEnum getEnum(String value){
AnotherEnum anotherEnum = null;
AnotherEnum e[] = AnotherEnum.values();
for (int i = 0; i < e.length; i++) {
if(e[i].value.equals(value)){
anotherEnum = e[i];
break;
}
}
return anotherEnum;
}
public static void main(String[] args) {
System.out.println(AnotherEnum.getEnum("BQY").getDiscription()+";discription:"+AnotherEnum.getEnum("BQY").getValue());
}
// 二
public enum Opration{
OPRATION_SERVER_CHECK,
OPRATION_SERVER_DB,
OPRATION_SERVER_SEREVICES,
OPRATION_SERVER_PUSHTO_STREAM;
}
}
以上是关于枚举使用的主要内容,如果未能解决你的问题,请参考以下文章