Java Utility Library

Java Locale - getScript() Method



The java.util.Locale.getScript() method returns the script for this locale, which should either be the empty string or an ISO 15924 4-letter script code. The first letter is uppercase and the rest are lowercase, for example, 'Latn', 'Cyrl'.

Syntax

public String getScript()

Parameters

No parameter is required.

Return Value

Returns the script code, or the empty string if none is defined.

Exception

NA

Example:

In the example below, the java.util.Locale.getScript() method is used to get the script code of the given Locale.

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

The output of the above code will be:

loc is: zh_CN_#Hans
Script Code is: Hans

❮ Java.util - Locale