Java Utility Library

Java Locale - getDisplayScript() Method



The java.util.Locale.getDisplayScript() method returns a name for the locale's script that is appropriate for display to the user. If possible, the name will be localized for the given locale. Returns the empty string if this locale doesn't specify a script code.

Syntax

public String getDisplayScript(Locale inLocale)

Parameters

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

Return Value

Returns the display name of the script code for the current default DISPLAY locale.

Exception

Throws NullPointerException, if inLocale is null.

Example:

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

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a locale
    Locale loc = Locale.forLanguageTag("zh-Hans-CN");

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

    //printing the name of the script
    //based on specified inLocale
    System.out.println("Script is: " + loc.getDisplayScript(Locale.GERMANY));
  }
}

The output of the above code will be:

loc is: zh_CN_#Hans
Script is: Vereinfacht

❮ Java.util - Locale