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 final String getDisplayName()

Parameters

No parameter is required.

Return Value

Returns the name of the locale appropriate to display.

Exception

NA

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

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

    //printing the name of the locale
    System.out.println("Name is: " + loc.getDisplayName());
  }
}

The output of the above code will be:

loc is: en_UK
Name is: English (UK)

❮ Java.util - Locale