Java中java.util.Locale.Builder类的setUnicodeLocaleKeyword()方法用于将此Locale.Builder设置为指定的unicodeLocaleKeyword键。这意味着此方法将设置Locale.Builder实例的当前unicodeLocaleKeyword,以匹配提供的unicodeLocaleKeyword键,并键入并返回它。如果指定的unicodeLocaleKeyword为null或为空,则将删除此LocaleBuilder的unicodeLocaleKeyword。
用法:
public Locale.Builder setUnicodeLocaleKeyword( String unicodeLocaleKeywordKey, String unicodeLocaleKeywordType)
参数:此方法接受两个参数:
- unicodeLocaleKey:这是要为Unicode语言环境设置为此Locale.Builder实例的键String。
- unicodeLocaleKeywordType:这是将设置为Unicode语言环境的此Locale.Builder实例的String类型。
返回类型:此方法返回一个Locale.Builder实例,并将此Locale.Builder的unicodeLocaleKeyword集设置为指定的unicodeLocaleKeyword。
异常:此方法引发以下异常:
- IllformedLocaleException:如果指定的unicodeLocaleKeyword具有任何格式错误的字段
程序1:
// Java program to demonstrate
// the above method
import java.util.*;
import java.util.Locale.*;
public class LocaleBuilderDemo {
public static void main(String[] args)
{
// Creating a new Locale.Builder
Locale.Builder localeBuilder
= new Builder();
// Displaying Locale.Builder
System.out.println("LocaleBuilder:"
+ localeBuilder);
// setting the unicodeLocaleKeyword
// of Locale.Builder
String unicodeLocaleKeywordKey = "nu";
String unicodeLocaleKeywordType = "thai";
System.out.println("Setting the "
+ "unicodeLocaleKeyword:"
+ unicodeLocaleKeywordKey + "-"
+ unicodeLocaleKeywordType);
localeBuilder
= localeBuilder
.setUnicodeLocaleKeyword(
unicodeLocaleKeywordKey,
unicodeLocaleKeywordType);
// Displaying Locale.Builder
System.out.println("Updated LocaleBuilder:"
+ localeBuilder);
}
}
输出:
LocaleBuilder:java.util.Locale$Builder@232204a1 Setting the unicodeLocaleKeyword:nu-thai Updated LocaleBuilder:java.util.Locale$Builder@232204a1
程序2:
// Java program to demonstrate
// the above method
import java.util.*;
import java.util.Locale.*;
public class LocaleBuilderDemo {
public static void main(String[] args)
{
// Creating a new Locale.Builder
Locale.Builder localeBuilder
= new Builder();
// Displaying Locale.Builder
System.out.println("LocaleBuilder:"
+ localeBuilder);
// setting the unicodeLocaleKeyword
// of Locale.Builder
String unicodeLocaleKeywordKey = "asf@";
String unicodeLocaleKeywordType = "afaf$";
System.out.println("Setting the "
+ "unicodeLocaleKeyword:"
+ unicodeLocaleKeywordKey + "-"
+ unicodeLocaleKeywordType);
try {
localeBuilder
= localeBuilder
.setUnicodeLocaleKeyword(
unicodeLocaleKeywordKey,
unicodeLocaleKeywordType);
// Displaying Locale.Builder
System.out.println("Updated LocaleBuilder:"
+ localeBuilder);
}
catch (Exception e) {
System.out.println(e);
}
}
}
输出:
LocaleBuilder:java.util.Locale$Builder@232204a1 Setting the unicodeLocaleKeyword:asf@-afaf$ java.util.IllformedLocaleException: Ill-formed Unicode locale keyword key: asf@ [at index 0]
相关用法
- Java Java.util.Collections.rotate()用法及代码示例
- Java Java lang.Long.highestOneBit()用法及代码示例
- Java Java lang.Long.byteValue()用法及代码示例
- Java Java.util.Collections.disjoint()用法及代码示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
- Java Java lang.Long.reverse()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Clock tickMinutes()用法及代码示例
- Java Clock withZone()用法及代码示例
- Java Set add()用法及代码示例
- Java Set contains()用法及代码示例
注:本文由纯净天空筛选整理自Code_r大神的英文原创作品 Locale.Builder setUnicodeLocaleKeyword() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。