The Java Locale hasExtensions() method returns true if this Locale has any extensions.
DeclarationFollowing is the declaration for java.util.Locale.hasExtensions() method
public boolean hasExtensions()Parameters
NA
Return ValueThis method returns true if this Locale has any extensions.
ExceptionNA
Checking if Locale has Extension or Not ExampleThe following example shows the usage of Java Locale hasExtensions() method. We're creating two locale objects, one with with extension and another without extension. Then we'll check their status using hasExtensions() method and printed.
package com.tutorialspoint; import java.util.Locale; import java.util.Locale.Builder; public class LocaleDemo { public static void main(String[] args) { // create a new locale Locale locale1 = new Builder().setExtension('a', "sample-ex-tension").build(); Locale locale2 = Locale.US; if(locale1.hasExtensions()){ System.out.println("Locale 1 has extensions"); } if(locale2.hasExtensions()){ System.out.println("Locale 2 has extensions"); } } }Output
Let us compile and run the above program, this will produce the following result −
Locale 1 has extensions
java_util_locale.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4