Java Utility Library

Java Locale - getDisplayCountry() Method



The java.util.Locale.getDisplayCountry() method returns a name for the locale's country that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale.

Syntax

public String getDisplayCountry(Locale inLocale)

Parameters

inLocale Specify the locale for which to retrieve the display country.

Return Value

Returns the name of the country appropriate to the given locale.

Exception

Throws NullPointerException, if inLocale is null.

Example:

In the example below, the java.util.Locale.getDisplayCountry() method is used to get the name of the country of a given locale.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a locale
    Locale loc = new Locale("EN", "US");

    //printing the locale
    System.out.println("loc is: " + loc);

    //printing the name of the country 
    //based on specified inLocale
    System.out.println("Country is: " + loc.getDisplayCountry(Locale.GERMANY));
  }
}

The output of the above code will be:

loc is: en_US
Country is: Vereinigte Staaten

❮ Java.util - Locale