Java Utility Library

Java Locale - getDisplayName() Method



The java.util.Locale.getDisplayName() method returns a name for the locale that is appropriate for display to the user. This will be the values returned by getDisplayLanguage(), getDisplayScript(), getDisplayCountry(), and getDisplayVariant() assembled into a single string.

Syntax

public String getDisplayName(Locale inLocale)

Parameters

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

Return Value

Returns the name of the locale appropriate to display.

Exception

Throws NullPointerException, if inLocale is null.

Example:

In the example below, the java.util.Locale.getDisplayName() method is used to get the name of the 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 locale 
    //based on specified inLocale
    System.out.println("Name is: " + loc.getDisplayName(Locale.GERMANY));
  }
}

The output of the above code will be:

loc is: en_US
Name is: Englisch (Vereinigte Staaten)

❮ Java.util - Locale