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 default DISPLAY locale. Returns the empty string if this locale doesn't specify a script code.

Syntax

public final String getDisplayScript()

Parameters

No parameter is required.

Return Value

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

Exception

NA

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
    System.out.println("Script is: " + loc.getDisplayScript());
  }
}

The output of the above code will be:

loc is: zh_CN_#Hans
Script is: Simplified

❮ Java.util - Locale