当前位置:网站首页>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();
}
}
边栏推荐
- CBAM learning notes
- Common shortcut keys and setting methods of idea
- Simple manual implementation of map
- Lvs+kept highly available cluster
- After sorting (bubble sorting), learn to continuously update other sorting methods
- XML writing gap animation popupwindow realizes the animation of emergence and exit
- IDEA常用快捷键及设置方法
- [2022 Niuke multi School Game 2] k-link with bracket sequence I
- 对L1正则化和L2正则化的理解[通俗易懂]
- 聊聊 MySQL 事务二阶段提交
猜你喜欢

LM NAV: robot navigation method based on large models of language, vision and behavior

高并发遇到死锁了,如何搞?

一文读懂Plato Farm的ePLATO,以及其高溢价缘由

8000字讲透OBSA原理与应用实践

How can anyone ask how MySQL archives data?

Small change project (two versions) with detailed ideas

Can JVM tuning be done with single core CPU and 1G memory?

零钱通项目(两个版本)含思路详解

Idea connects to MySQL database and performs SQL query operations

CBAM learning notes
随机推荐
软件测试面试题:假设有一个文本框要求输入10个字符的邮政编码,对于该文本框应该怎样划分等价类?
看起来是线程池的BUG,但是我认为是源码设计不合理。
软件测试面试题:什么是回归测试?
Tencent cloud [hiflow] | automation --------- hiflow: still copying and pasting?
IDEA连接MySQL数据库并执行SQL查询操作
Mobilevit learning notes
C语言-入门-语法-指针(十二)
Openai issued a document to introduce the latest application of Dall · E 2: fully enter the field of artistic creation and design
University of Tilburg, Federal University of the Netherlands | neural data to text generation based on small datasets: comparing the added value of two semi supervised learning approvals on top of a l
8000 word explanation of OBSA principle and application practice
单核CPU, 1G内存,也能做JVM调优吗?
Oppo core making plan officially announced: the first chip or oppo M1
为什么要使用MQ消息中间件?这几个问题必须拿下
软件测试面试题:请说出这些测试最好由那些人员完成,测试的是什么?
除了「加机器」,其实你的微服务还能这样优化
XML writing gap animation popupwindow realizes the animation of emergence and exit
Internal class (detailed explanation of four internal classes)
Daily news on July 15, 2022: meta announced the launch of make-a-scene: AI image generation can be controlled based on text and sketches
学完4种 Redis 集群方案要多久?我一口气给你说完
软件测试面试题:设计测试用例时应该考虑哪些方面,即不同的测试用例针对那些方面进行测试?