我在哪里可以找到标准化的美国和加拿大省Java Map,全名的缩写 [英] Where can I find a standardized US States and Canadian Provinces Java Map, abbreviations to full names
问题描述
我需要一个Java词典来从北美州和省的缩写中查找州和省的完整名称.例如,"TX"表示->得克萨斯州","NS"州->新斯科舍省".
I need a Java dictionary to look up full state and province names from North American state and province abbreviations. For example, "TX" --> "Texas", "NS" --> "Nova Scotia".
我在这里找到了C#版本:标准化的美国州阵列和国家数组
I found the C# versions here: Standardized US States Array and Countries Array
使用Map集合的Java版本是什么?
What is the Java version using the Map collection?
推荐答案
这是Java词典,将美国州和加拿大省的缩写映射为全名,并改编自问题中提到的C#版本.为了简洁起见,它使用静态初始化.
Here is the Java dictionary, mapping US state and Canadian province abbreviations to full names, adapted from the C# versions mentioned in the question. It uses static initialization for brevity.
// 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引入了不可变映射,这是实现为不可变映射的同一词典:
Java 9 introduced immutable maps and here is the same dictionary implemented as an immutable map:
// 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"));
这篇关于我在哪里可以找到标准化的美国和加拿大省Java Map,全名的缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!