getDisplayScript(): This method is available in java.util.Locale class of Java.
Syntax:
String java.util.Locale.getDisplayScript(Locale inLocale)
This method takes one argument of type Locale as its parameter. This method returns a name for the locale's script that is appropriate for display to the user.
Note: Returns the empty string if this locale doesn't specify a script code.
Parameters: One parameter is required for this method.
inLocale: The locale for which to retrieve the display script.
Returns: the display name of the script code for the current default DISPLAY locale.
Throws: NullPointerException - if inLocale is null.
For Example:
Locale locale = new Locale("en", "USA")
Locale inLocale = new Locale("fr", "FR")
locale.getDisplayScript(inLocale) = > It returns empty String.
Approach 1: When inLocale is not null.
Java
import java.util.Locale;public class LocalegetDisplayScript2 {public static void main(String[] args) {Locale locale = new Locale("en", "USA");Locale inLocale = new Locale("fr", "FR");System.out.println("Script is " +locale.getDisplayScript(inLocale));}}
Output:
Script is
Approach 2: When inLocale is null.
Java
import java.util.Locale;public class LocalegetDisplayScript2 {public static void main(String[] args) {Locale locale = new Locale("en", "USA");Locale inLocale = null;System.out.println("Script is " +locale.getDisplayScript(inLocale));}}
Output:
Exception in thread "main" java.lang.NullPointerException at java.base/java.util.Objects.requireNonNull(Objects.java:208) at java.base/java.util.Locale.getDisplayString(Locale.java:1917) at java.base/java.util.Locale.getDisplayScript(Locale.java:1870)
No comments:
Post a Comment