简体   繁体   中英

Locale and ISO3CountryCodes

I have seen recently in java 1.7 that if I loop on Locales and get the ISO3Country code for the same then for Locale "CS" it gives me error "couldn't find 3 letter country code CS". Is it expected behavior? I also tested in java 1.6 but there I am not getting this error.

Locales[] locales =        GregorianCalender.getAvailableLocales();
For(Locale l: locales){
     System.out.println(l.getISO3CountryCode());
  }  

The short answer is: This is a country code for a country that no longer exists (Serbia and Montenegro), so the behavior may indeed be indeterminate.

ISO-3166 is divided into three parts. The first part, ISO-3166-1, defines these country codes and, in turn, has several parts. The most relevant here are ISO-3166-1 alpha-2 and ISO-3166-1 alpha-3 which define the 2 and 3-letter country codes, respectively.

According to the alpha-2 table, "CS" is the country code for Serbia and Montenegro, a country that no longer exists. It still has an entry in alpha-2, marked as "reserved for deletion", for backwards compatibility purposes. It is probably also still in Java for backwards compatibility.

The equivalent entry in alpha-3 is "SCG" and is also be marked as reserved. I would expect this code to be returned to you, but can understand why it might not be. (Alternatively, ISO-3166-3 defines country codes for countries that no longer exist; they are four letters long and maybe "CSXX" is what should be returned here...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM