方式1

Demo

import com.google.common.collect.Lists;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

public enum StandardOperationEntityType {

CREATE("CODELIST", "数据字典"),

DELETE("CODELIST_ITEM", "数据字典项");

private final String code;

private final String name;

public final static String CODE_PARAM = "code";

public final static String NAME_PARAM = "name";

StandardOperationEntityType(String code, String name){

this.code = code;

this.name = name;

}

public static StandardOperationEntityType findByCode(String code) {

for (StandardOperationEntityType type : values()) {

if (type.getCode().equals(code)) {

return type;

}

}

return null;

}

public static StandardOperationEntityType findByName(String name) {

for (StandardOperationEntityType type : values()) {

if (type.getName().equals(name)) {

return type;

}

}

return null;

}

public String getCode() {

return this.code;

}

public String getName() {

return this.name;

}

public static List> toList() {

List> list = Lists.newArrayList();//Lists.newArrayList()其实和new ArrayList()几乎一模

for (StandardOperationEntityType item : StandardOperationEntityType.values()) {

Map map = new HashMap();

map.put(StandardOperationEntityType.CODE_PARAM, item.getCode());

map.put(StandardOperationEntityType.NAME_PARAM, item.getName());

list.add(map);

}

return list;

}

}

方式2

StandardOperationEntityType [] array = StandardOperationEntityType.values();

List list = Arrays.asList(array);

Set set= new HashSet<>( list );

//Set set= new HashSet<>( Arrays.asList(StandardOperationEntityType.values()) );

X 参考文献

Java循环遍历枚举类型

推荐阅读

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。