Locale.Builder setUnicodeLocaleKeyword() method in Java with Examples
The setUnicodeLocaleKeyword() method of java.util.Locale.Builder class in Java is used to set this Locale.Builder to the specified unicodeLocaleKeyword key. It means that this method will set the current unicodeLocaleKeyword of Locale.Builder instance to match the provided unicodeLocaleKeyword key and type and return it. If the specified unicodeLocaleKeyword is null or empty, then the unicodeLocaleKeyword of this LocaleBuilder is removed.
Syntax:
public Locale.Builder
setUnicodeLocaleKeyword(
String unicodeLocaleKeywordKey,
String unicodeLocaleKeywordType)
Parameter: This method accepts two parameters:
- unicodeLocaleKey: which is the key String that is to be set to this Locale.Builder instance for the unicode Locale
- unicodeLocaleKeywordType: which is the type String that is to be set to this Locale.Builder instance for the unicode Locale
Return Type: This method returns an Locale.Builder instance with the unicodeLocaleKeyword set of this Locale.Builder to the specified unicodeLocaleKeyword.
Exception: This method throws following Exceptions:
- IllformedLocaleException: if the specified unicodeLocaleKeyword has any ill formed fields
Program 1:
import java.util.*;
import java.util.Locale.*;
public class LocaleBuilderDemo {
public static void main(String[] args)
{
Locale.Builder localeBuilder
= new Builder();
System.out.println( "LocaleBuilder: "
+ localeBuilder);
String unicodeLocaleKeywordKey = "nu" ;
String unicodeLocaleKeywordType = "thai" ;
System.out.println( "Setting the "
+ "unicodeLocaleKeyword: "
+ unicodeLocaleKeywordKey + "-"
+ unicodeLocaleKeywordType);
localeBuilder
= localeBuilder
.setUnicodeLocaleKeyword(
unicodeLocaleKeywordKey,
unicodeLocaleKeywordType);
System.out.println( "Updated LocaleBuilder: "
+ localeBuilder);
}
}
|
Output:
LocaleBuilder: java.util.Locale$Builder@232204a1
Setting the unicodeLocaleKeyword: nu-thai
Updated LocaleBuilder: java.util.Locale$Builder@232204a1
Program 2:
import java.util.*;
import java.util.Locale.*;
public class LocaleBuilderDemo {
public static void main(String[] args)
{
Locale.Builder localeBuilder
= new Builder();
System.out.println( "LocaleBuilder: "
+ localeBuilder);
String unicodeLocaleKeywordKey = "asf@" ;
String unicodeLocaleKeywordType = "afaf$" ;
System.out.println( "Setting the "
+ "unicodeLocaleKeyword: "
+ unicodeLocaleKeywordKey + "-"
+ unicodeLocaleKeywordType);
try {
localeBuilder
= localeBuilder
.setUnicodeLocaleKeyword(
unicodeLocaleKeywordKey,
unicodeLocaleKeywordType);
System.out.println( "Updated LocaleBuilder: "
+ localeBuilder);
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Output:
LocaleBuilder: java.util.Locale$Builder@232204a1
Setting the unicodeLocaleKeyword: asf@-afaf$
java.util.IllformedLocaleException:
Ill-formed Unicode locale keyword key:
asf@ [at index 0]
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/Locale.Builder.html#setUnicodeLocaleKeyword-java.lang.String-java.lang.String-
Last Updated :
30 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...