Locale getDisplayCountry() in Java

getDisplayCountry(): This method is available in java.util.Locale class of Java.

Syntax:

String java.util.Locale.getDisplayCountry()

This method returns a name for the locale's country that is appropriate for display to the user.

Note: If the locale doesn't specify a country, this function returns the empty string.

Returns: The name of the country appropriate to the locale.

For Example:

Locale locale = new Locale("en", "IN")

locale.getDisplayCountry() = > It returns INDIA.

Approach

Java

import java.util.Locale;

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

        Locale locale = new Locale("en""IN");

        System.out.println("Country is " + 
locale.getDisplayCountry());

    }
}

Output:

Country is India

No comments:

Post a Comment