Java Utility Library

Java Locale - getDisplayLanguage() Method



The java.util.Locale.getDisplayLanguage() method returns a name for the locale's language that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale.

Syntax

public String getDisplayLanguage(Locale inLocale)

Parameters

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

Return Value

Returns the name of the display language appropriate to the given locale.

Exception

Throws NullPointerException if inLocale is null.

Example:

In the example below, the java.util.Locale.getDisplayLanguage() method is used to get the name of the given locale's language.

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 language
    //based on specified inLocale
    System.out.println("Language is: " + loc.getDisplayLanguage(Locale.GERMANY));
  }
}

The output of the above code will be:

loc is: en_UK
Language is: Englisch

❮ Java.util - Locale