package com.-.it.regioc.bean.enums; public enum CountryMapping { AD("AD", "安道尔"), AE("AE", "阿拉伯联合酋长国"), AF("AF", "阿富汗"), ZA("ZA", "南非"), ZM("ZM", "赞比亚"), ZW("ZW", "津巴布韦"); private final String enName; private final String cnName; CountryMapping(String enName, String cnName) { this.enName = enName; this.cnName = cnName; } /** * 根据中文名明返回英文名 */ public static String getEnNameByCnName(String cnName) { for (CountryMapping value : CountryMapping.values()) { if (value.getCnName().equals(cnName)) { return value.getEnName(); } } return null; } /** * 根据英文名返回中文名 */ public static String getCnNameByEnName(String enName) { for (CountryMapping value : CountryMapping.values()) { if (value.getEnName().equals(enName)) { return value.getCnName(); } } return null; } public String getEnName() { return enName; } public String getCnName() { return cnName; } } @Test public void test26() { String cnName = CountryMapping.AD.getCnName(); System.out.println(cnName); String enNameByCnName = CountryMapping.getEnNameByCnName("德国"); System.out.println(enNameByCnName); }
标签:return,String,cnName,CountryMapping,public,enName From: https://www.cnblogs.com/mingruifeng/p/16967656.html