Locale getDisplayName() in Java

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

Syntax:

String java.util.Locale.getDisplayName()

This method returns a name for the locale that is appropriate for display to the user. If the language, script, country, and variant fields are all empty, this function returns the empty string. 

Returns: The name of the locale appropriate to display.

For Example:

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

locale.getDisplayName() = > It returns English (USA).

Approach

Java

import java.util.Locale;

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

        Locale locale = new Locale("en""USA");
        System.out.println(locale.getDisplayName());
    }
}

Output:

English (USA)

No comments:

Post a Comment