반응형
public enum Company {
COMPANY_01("01", "카카오"),
COMPANY_02("02", "네이버"),
COMPANY_03("03", "GS25"),
COMPANY_04("04", "넥슨"),
COMPANY_05("05", "애플"),
String code;
String desc;
Company(String code, String desc) {
this.code = code;
this.desc = desc;
}
public String getCode() {
return code;
}
public String getDesc() {
return desc;
}
}
//map에 담음
public static final Map<String, String> companyMap = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(Company::getCode, Company::getDesc)));
//map에 넣은 뒤 특정 값 찾기
public static String findDesc(String description) {
return Optional.ofNullable(companyMap.get(description)).orElse("UNKNOWN");
}
//enum list에 담기
List<SelectBoxVo> list = new ArrayList<>(){};
for(Company code : Stream.of(Company.values()).collect(Collectors.toList())){
list.add(SelectBoxVo.builder().code(code.getCode()).label(code.getDesc()).build());
}
반응형
'Development > 기타' 카테고리의 다른 글
Intellj 미사용 import 자동 제거 (0) | 2023.03.31 |
---|---|
Intellj github 계정 여러개 사용하기 (0) | 2023.03.31 |
Cause: invalid source release: 11 (1) | 2022.02.08 |
개발자의 글쓰기 - 테크니컬 라이팅(technical writing) (0) | 2022.02.07 |
Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime / Node-sass incompatible with ^4.0.0. (0) | 2022.01.27 |