Is there an open source java enum of ISO 3166-1 country codes

前端 未结 11 2638
南笙
南笙 2020-12-04 10:57

Does anyone know of a freely available java 1.5 package that provides a list of ISO 3166-1 country codes as a enum or EnumMap? Specifically I need the \"ISO 3166-1-alpha-2

11条回答
  •  误落风尘
    2020-12-04 11:11

    There is an easy way to generate this enum with the language name. Execute this code to generate the list of enum fields to paste :

     /**
      * This is the code used to generate the enum content
      */
     public static void main(String[] args) {
      String[] codes = java.util.Locale.getISOLanguages();
      for (String isoCode: codes) {
       Locale locale = new Locale(isoCode);
       System.out.println(isoCode.toUpperCase() + "(\"" + locale.getDisplayLanguage(locale) + "\"),");
      }
     }
    

提交回复
热议问题