当前位置:网站首页>枚举Enum的简单使用
枚举Enum的简单使用
2022-07-27 18:56:00 【姓王字氐之】
1. 当枚举值为枚举本身
例:
public enum TestEnum {
ONE,TWO,THREE;
}
调用:
TestEnum.ONE

控制台打印
2. 当枚举值为自定义值
public enum TestEnum {
ONE(1),TWO(2),THREE(3);
private Integer numb;
// 构造函数
TestEnum(int numb) {
this.numb = numb;
}
// 导出值
public Integer getNumb() {
return numb;
}
}
调用:
TestEnum.ONE.getNumb()

控制台打印
3. 枚举的枚举值存在多个
例:
package com.api.system.enums;
/** * @author king */
public enum WsEnum {
SADJ("SADJ","一号枚举"),
LAJD("LAJD","二号枚举"),
KYBG("KYBG","三号枚举"),
KYQD("KYQD","四号枚举"),
SJBG("SJBG", "五号枚举"),
SJQD("SJQD","六号枚举"),
SJGK("SJGK","七号枚举"),
FHQD("FHQD", "八号枚举"),
ZJBQ("ZJBQ","九号枚举"),
BQQD("BQQD","十号枚举");
private String id;
private String name;
WsEnum(String id, String name) {
}
public String getId() {
return id;
}
public String getName() {
return name;
}
//通过枚举id查询当前枚举,可用for循环替换
public static WsEnum getEnum(String id) {
Optional<WsEnum> wsEnum = Arrays.stream(WsEnum.values()).filter(x -> x.getId().equals(id)).findFirst();
return wsEnum.get();
}
// 通过枚举name查询当前枚举,可用for循环替换
public static WsEnum getEnumByName(String name) {
Optional<WsEnum> wsEnum = Arrays.stream(WsEnum.values()).filter(x -> x.getName().equals(name)).findFirst();
return wsEnum.get();
}
}
边栏推荐
- Command line PDF Converter::: fcoder 2PDF
- Comprehensively design an oppe homepage -- Design of selected accessories on the page
- 数字化工厂管理系统有哪些价值
- Dobot Magician 机器臂-简介
- Postgresql源码(65)新快照体系Globalvis工作原理分析
- crsctl中,显示的HOME的作用
- ACM mm 2022 | Zhejiang University proposed: point cloud segmentation, active learning of new SOTA
- 数字化工厂系统有什么现实优势
- 综合设计一个OPPE主页--页面的搜素欧珀部分的样式
- Force buckle 919. Complete binary tree inserter
猜你喜欢

Leetcode daily practice - 203. remove linked list elements

The new CTO strongly prohibits the use of calendar?

Puzzle (021) eliminate problems

The solution that the laptop can connect to WiFi but the browser cannot open the web page

JVM-内存模型 面试总结

Instructions - Worthington reverse transcriptase, recombinant HIV testing program

What is the value of digital factory management system

MAPGIS 3D scene rendering technology and Application

数字化工厂管理系统有哪些价值

说明书丨Worthington逆转录酶、重组 HIV 检测方案
随机推荐
Leetcode daily practice - cm11 linked list segmentation
Puzzle (002) inner solid, outer solid, Hamilton
Worthington蘑菇多酚氧化酶的特性及测定方案
How to speed up the memory database through special data type index
Big guys, the MySQL version is low and does not support CDC, so canal synchronizes binlog to Kafka and data to cli
用伪元素before实现元素的等比例缩放
mysql 最大建议行数2000w,靠谱吗?
How to check whether there is Tsinghua source / delete Tsinghua source and keep the default source
Leetcode daily practice - 203. remove linked list elements
监听服务器jar运行,及重启脚本
Worthington毒液中核酸外切酶的特征及相关文献
中英文说明书丨人甲胎蛋白(AFP)ELISA定量试剂盒
使用百度飞桨EasyDL实现电商UGC图片自动分类
工程技术开发的圈套与局限性
Automatic classification of e-commerce UGC pictures using Baidu PaddlePaddle easydl
One of IOU target tracking: IOU tracker
PostgreSQL source code (65) analysis of the working principle of globalvis, a new snapshot system
R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses deviance function to calculate the sum of squares of residual
中国能否在元宇宙的未来发展中取得突破,占领高地?
QModbus库使用,并作为ROS节点发布话题及程序CMakelist编写