getDisplayLanguage(): This method is available in java.util.Locale class of Java.
Syntax:
String java.util.Locale.getDisplayLanguage(Locale inLocale)
This method takes one argument of type Locale as its parameter. This method returns a name for the locale's language that is appropriate for display to the user.
Parameters: One parameter is required for this method.
inLocale: The locale for which to retrieve the display language.
Returns: The name of the display language appropriate to the given locale.
Throws: NullPointerException - if inLocale is null.
For Example:
Locale locale = new Locale("en", "USA")
Locale inLocale = new Locale("fr", "FR")
locale.getDisplayLanguage() = > It returns anglais.
Approach: When inLocale is not null.
Java
import java.util.Locale;public class LocalegetDisplayLanguage2 {public static void main(String[] args) {Locale locale = new Locale("en", "USA");Locale inLocale = new Locale("fr", "FR");System.out.println(locale.getDisplayLanguage(inLocale));}}
Output:
anglais
Approach: When inLocale is null.
Java
import java.util.Locale;public class LocalegetDisplayLanguage2 {public static void main(String[] args) {Locale locale = new Locale("en", "USA");Locale inLocale = null;System.out.println(locale.getDisplayLanguage(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.getDisplayLanguage(Locale.java:1840)
No comments:
Post a Comment