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.

Syntax

public final String getDisplayCountry()

Parameters

No parameter is required.

Return Value

Returns the name of the country appropriate to the locale.

Exception

NA

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", "UK");

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

    //printing the name of the country
    System.out.println("Country is: " + loc.getDisplayCountry());
  }
}

The output of the above code will be:

loc is: en_UK
Country is: UK

❮ Java.util - Locale