Java Locale getISOCountries() Method



Description

The Java Locale getISOCountries() method returns a list of all 2-letter country codes defined in ISO 3166. This can be used to create Locales.

Declaration

Following is the declaration for java.util.Locale.getISOCountries() method

public static String[] getISOCountries()

Parameters

NA

Return Value

This method returns the arrays of country codes.

Exception

NA

Getting Array of ISO Countries from Locale Example

The following example shows the usage of Java Locale getISOCountries() method. We're printing a list of 2 letter country codes as defined in ISO 3166.

package com.tutorialspoint;

import java.util.Locale;

public class LocaleDemo {
   public static void main(String[] args) {

      // get ISO countries
      String[] countries = Locale.getISOCountries();

      // print countries
      System.out.println("Countries are:");
      
      for (int i = 0; i < countries.length; i++) {
         System.out.println(i + ":" + countries[i]);
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Countries are:
0:AD
1:AE
2:AF
3:AG
4:AI
...
248:ZW
java_util_locale.htm
Advertisements