当前位置:网站首页>Simple use of enum
Simple use of enum
2022-07-27 21:47:00 【Surname Wang Zi dizhi】
1. When the enumeration value is the enumeration itself
example :
public enum TestEnum {
ONE,TWO,THREE;
}
call :
TestEnum.ONE

Console printing 
2. When the enumeration value is a user-defined value
public enum TestEnum {
ONE(1),TWO(2),THREE(3);
private Integer numb;
// Constructors
TestEnum(int numb) {
this.numb = numb;
}
// Export value
public Integer getNumb() {
return numb;
}
}
call :
TestEnum.ONE.getNumb()

Console printing 
3. There are multiple enumeration values of enumeration
example :
package com.api.system.enums;
/** * @author king */
public enum WsEnum {
SADJ("SADJ"," Enumeration number one "),
LAJD("LAJD"," Enumeration number two "),
KYBG("KYBG"," Enumeration number three "),
KYQD("KYQD"," Enumeration number four "),
SJBG("SJBG", " Enumeration number five "),
SJQD("SJQD"," Enumeration number six "),
SJGK("SJGK"," Enumeration number seven "),
FHQD("FHQD", " Enumeration number eight "),
ZJBQ("ZJBQ"," Enumeration number nine "),
BQQD("BQQD"," Enumeration number ten ");
private String id;
private String name;
WsEnum(String id, String name) {
}
public String getId() {
return id;
}
public String getName() {
return name;
}
// By enumeration id Query the current enumeration , You can use for Cyclic replacement
public static WsEnum getEnum(String id) {
Optional<WsEnum> wsEnum = Arrays.stream(WsEnum.values()).filter(x -> x.getId().equals(id)).findFirst();
return wsEnum.get();
}
// By enumeration name Query the current enumeration , You can use for Cyclic replacement
public static WsEnum getEnumByName(String name) {
Optional<WsEnum> wsEnum = Arrays.stream(WsEnum.values()).filter(x -> x.getName().equals(name)).findFirst();
return wsEnum.get();
}
}
边栏推荐
- Graphic SQL, this is too vivid!
- After sorting (bubble sorting), learn to continuously update other sorting methods
- 枚举和注解
- 软件测试面试题:软件验收测试包括正式验收测试、alpha测试、beta测试三种测试?
- B站崩了,如果我们是那晚负责修复的开发人员
- Cocoapods reload
- 排序(冒泡排序)后面学习持续更新其它排序方法
- 对L1正则化和L2正则化的理解[通俗易懂]
- 软件测试面试题:软件测试项目从什么时候开始?为什么?
- Software testing interview question: what is regression testing?
猜你喜欢
随机推荐
软件测试面试题:假设有一个文本框要求输入10个字符的邮政编码,对于该文本框应该怎样划分等价类?
day 1 - day 4
In depth understanding of recursive method calls (including instance maze problem, tower of Hanoi, monkey eating peach, fiboracci, factorial))
面向3nm及以下工艺,ASML新一代EUV光刻机曝光
Ziguang zhanrui: dozens of 5g terminals based on chunteng 510 will be commercially available in 2020
Pytest failed and rerun
In addition to "adding machines", in fact, your micro service can be optimized like this
内部类(四种内部类详解)
@The difference between Autowired annotation and @resource annotation
2019Q4内存厂商营收排名:三星下滑5%,仅SK海力士、美光维持增长
聊聊 MySQL 事务二阶段提交
Shengyang technology officially launched the remote voiceprint health return visit service system!
纳微半导体65W 氮化镓(GaN)方案获小米10 Pro充电器采用
Unit-- read Excel
怎么还有人问 MySQL 是如何归档数据的呢?
零钱通项目(两个版本)含思路详解
2021-11-05 understand main method syntax, code block and final keyword
JVM-内存模型 面试总结
Technical practice behind bloom model: how to refine 176billion parameter model?
Analysis of STL source code







