在哪里可以找到标准化的美国各州和加拿大各省Java地图,缩写为全名



我需要一本Java字典来查找北美州和省缩写中的完整州和省名称。例如;TX"-->quot;德克萨斯州"NS"-->quot;Nova Scotia";。

我在这里找到了C#版本:标准化的美国国家阵列和国家阵列

使用Map集合的Java版本是什么?

这是Java字典,将美国州和加拿大省的缩写映射为全名,改编自问题中提到的C#版本。为了简洁起见,它使用了静态初始化。

// the US State and Canada abbreviation dictionary, abbreviation --> full name
private final static Map<String, String>  stateAbbreviationDictionary = new HashMap<>();
static {
// USA
stateAbbreviationDictionary.put("AL", "Alabama");
stateAbbreviationDictionary.put("AK", "Alaska");
stateAbbreviationDictionary.put("AZ", "Arizona");
stateAbbreviationDictionary.put("AR", "Arkansas");
stateAbbreviationDictionary.put("CA", "California");
stateAbbreviationDictionary.put("CO", "Colorado");
stateAbbreviationDictionary.put("CT", "Connecticut");
stateAbbreviationDictionary.put("DE", "Delaware");
stateAbbreviationDictionary.put("DC", "District Of Columbia");
stateAbbreviationDictionary.put("FL", "Florida");
stateAbbreviationDictionary.put("GA", "Georgia");
stateAbbreviationDictionary.put("HI", "Hawaii");
stateAbbreviationDictionary.put("ID", "Idaho");
stateAbbreviationDictionary.put("IL", "Illinois");
stateAbbreviationDictionary.put("IN", "Indiana");
stateAbbreviationDictionary.put("IA", "Iowa");
stateAbbreviationDictionary.put("KS", "Kansas");
stateAbbreviationDictionary.put("KY", "Kentucky");
stateAbbreviationDictionary.put("LA", "Louisiana");
stateAbbreviationDictionary.put("ME", "Maine");
stateAbbreviationDictionary.put("MD", "Maryland");
stateAbbreviationDictionary.put("MA", "Massachusetts");
stateAbbreviationDictionary.put("MI", "Michigan");
stateAbbreviationDictionary.put("MN", "Minnesota");
stateAbbreviationDictionary.put("MS", "Mississippi");
stateAbbreviationDictionary.put("MO", "Missouri");
stateAbbreviationDictionary.put("MT", "Montana");
stateAbbreviationDictionary.put("NE", "Nebraska");
stateAbbreviationDictionary.put("NV", "Nevada");
stateAbbreviationDictionary.put("NH", "New Hampshire");
stateAbbreviationDictionary.put("NJ", "New Jersey");
stateAbbreviationDictionary.put("NM", "New Mexico");
stateAbbreviationDictionary.put("NY", "New York");
stateAbbreviationDictionary.put("NC", "North Carolina");
stateAbbreviationDictionary.put("ND", "North Dakota");
stateAbbreviationDictionary.put("OH", "Ohio");
stateAbbreviationDictionary.put("OK", "Oklahoma");
stateAbbreviationDictionary.put("OR", "Oregon");
stateAbbreviationDictionary.put("PA", "Pennsylvania");
stateAbbreviationDictionary.put("RI", "Rhode Island");
stateAbbreviationDictionary.put("SC", "South Carolina");
stateAbbreviationDictionary.put("SD", "South Dakota");
stateAbbreviationDictionary.put("TN", "Tennessee");
stateAbbreviationDictionary.put("TX", "Texas");
stateAbbreviationDictionary.put("UT", "Utah");
stateAbbreviationDictionary.put("VT", "Vermont");
stateAbbreviationDictionary.put("VA", "Virginia");
stateAbbreviationDictionary.put("WA", "Washington");
stateAbbreviationDictionary.put("WV", "West Virginia");
stateAbbreviationDictionary.put("WI", "Wisconsin");
stateAbbreviationDictionary.put("WY", "Wyoming");
// Canada
stateAbbreviationDictionary.put("AB", "Alberta");
stateAbbreviationDictionary.put("BC", "British Columbia");
stateAbbreviationDictionary.put("MB", "Manitoba");
stateAbbreviationDictionary.put("NB", "New Brunswick");
stateAbbreviationDictionary.put("NL", "Newfoundland and Labrador");
stateAbbreviationDictionary.put("NS", "Nova Scotia");
stateAbbreviationDictionary.put("NT", "Northwest Territories");
stateAbbreviationDictionary.put("NU", "Nunavut");
stateAbbreviationDictionary.put("ON", "Ontario");
stateAbbreviationDictionary.put("PE", "Prince Edward Island");
stateAbbreviationDictionary.put("QC", "Quebec");
stateAbbreviationDictionary.put("SK", "Saskatchewan");
stateAbbreviationDictionary.put("YT", "Yukon");
}

Java 9引入了不可变映射,这里有一个与不可变映射相同的字典:

// the US State and Canada abbreviation dictionary, abbreviation --> full name
private final static Map<String, String> stateAbbreviationDictionary = Map.ofEntries(
// USA
entry("AL", "Alabama"),
entry("AK", "Alaska"),
entry("AZ", "Arizona"),
entry("AR", "Arkansas"),
entry("CA", "California"),
entry("CO", "Colorado"),
entry("CT", "Connecticut"),
entry("DE", "Delaware"),
entry("DC", "District Of Columbia"),
entry("FL", "Florida"),
entry("GA", "Georgia"),
entry("HI", "Hawaii"),
entry("ID", "Idaho"),
entry("IL", "Illinois"),
entry("IN", "Indiana"),
entry("IA", "Iowa"),
entry("KS", "Kansas"),
entry("KY", "Kentucky"),
entry("LA", "Louisiana"),
entry("ME", "Maine"),
entry("MD", "Maryland"),
entry("MA", "Massachusetts"),
entry("MI", "Michigan"),
entry("MN", "Minnesota"),
entry("MS", "Mississippi"),
entry("MO", "Missouri"),
entry("MT", "Montana"),
entry("NE", "Nebraska"),
entry("NV", "Nevada"),
entry("NH", "New Hampshire"),
entry("NJ", "New Jersey"),
entry("NM", "New Mexico"),
entry("NY", "New York"),
entry("NC", "North Carolina"),
entry("ND", "North Dakota"),
entry("OH", "Ohio"),
entry("OK", "Oklahoma"),
entry("OR", "Oregon"),
entry("PA", "Pennsylvania"),
entry("RI", "Rhode Island"),
entry("SC", "South Carolina"),
entry("SD", "South Dakota"),
entry("TN", "Tennessee"),
entry("TX", "Texas"),
entry("UT", "Utah"),
entry("VT", "Vermont"),
entry("VA", "Virginia"),
entry("WA", "Washington"),
entry("WV", "West Virginia"),
entry("WI", "Wisconsin"),
entry("WY", "Wyoming"),
// Canada
entry("AB", "Alberta"),
entry("BC", "British Columbia"),
entry("MB", "Manitoba"),
entry("NB", "New Brunswick"),
entry("NL", "Newfoundland and Labrador"),
entry("NS", "Nova Scotia"),
entry("NT", "Northwest Territories"),
entry("NU", "Nunavut"),
entry("ON", "Ontario"),
entry("PE", "Prince Edward Island"),
entry("QC", "Quebec"),
entry("SK", "Saskatchewan"),
entry("YT", "Yukon"));

最新更新