The Java Locale stripExtensions() method returns a copy of this Locale with no extensions. If this Locale has no extensions, this Locale is returned.
DeclarationFollowing is the declaration for java.util.Locale.stripExtensions() method
public Locale stripExtensions()Parameters
NA
Return ValueThis method returns a copy of this Locale with no extensions, or this if this has no extensions.
ExceptionNA
Getting Copy of Locale without Extension ExampleThe following example shows the usage of Java Locale stripExtensions() method. We're creating a locale using Builder with a given extension with a key. Then using getExtension() method, extension is printed for an existing key. Now using stripExtensions() we're getting a copy of Locale without extensions and then check is made using getExtension() method to print the earlier existing value to be null.
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 locale = new Builder().setExtension('a', "sample-ex-tension").build(); // print the extension for 'a' System.out.println("Extension:" + locale.getExtension('a')); // create a extension free locale Locale locale1 = locale.stripExtensions(); // print the extension for 'a' System.out.println("Extension:" + locale1.getExtension('a')); } }Output
Let us compile and run the above program, this will produce the following result −
Extension:sample-ex-tension Extension:null
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