1.介绍
将枚举全部值转化成一个list
2.示例
public enum ChannelEnum {
/**
* 饿了么外卖
*/
ELEME("eleme","饿了么外卖"),
/**
* 美团外卖
*/
MTWM("mtwm","美团外卖"),
/**
* 京东外卖
*/
JDWM("jdwm","京东外卖"),
/**
* 百度外卖
*/
BDWM("bdwm","百度外卖");
ChannelEnum(String channelCode, String channelName){
this.channelCode = channelCode;
this.channelName = channelName;
}
private String channelCode;
private String channelName;
public String getChannelCode() {
return channelCode;
}
public void setChannelCode(String channelCode) {
this.channelCode = channelCode;
}
public String getChannelName() {
return channelName;
}
public void setChannelName(String channelName) {
this.channelName = channelName;
}
/**
* 将枚举值转化成list集合
*
* @return
*/
public static List<String> toList(){
List<String> list = new ArrayList<>();
for (ChannelEnum channelEnum: ChannelEnum.values()
) {
list.add(channelEnum.getChannelCode());
}
return list;
}
}
获取枚举集合:
/**
* 枚举集合
*/
private static List<String> list = ChannelEnum.toList();
3.例
image.png
网友评论