Java中的 Locale.FilteringMode valueOf() 方法及示例
Java中Java .util.Locale.FilteringMode枚举的valueOf()方法用于获取该Locale.FilteringMode枚举类型的指定常量的值。该方法以常量名作为参数。
句法:
public static Locale.FilteringMode valueOf(String name)
参数:此方法接受一个参数名称,该名称是常量名称,其值将从 Locale.FilteringMode 枚举中检索。
返回类型:此方法返回具有指定名称值的此Locale.FilteringMode枚举类型的实例。
异常:此方法不抛出任何异常。
方案一:
// Java program to demonstrate
// the above method
import java.util.*;
import java.util.Locale.*;
public class LocaleFilteringModeDemo {
public static void main(String[] args)
{
String name
= "AUTOSELECT_FILTERING";
// Getting the constant
// of Locale.FilteringMode
System.out.println("Locale.FilteringMode"
+ " value of "
+ name + ": "
+ Locale.FilteringMode
.valueOf(name));
}
}
输出:
Locale.FilteringMode value of AUTOSELECT_FILTERING: AUTOSELECT_FILTERING
方案二:
// Java program to demonstrate
// the above method
import java.util.*;
import java.util.Locale.*;
public class LocaleFilteringModeDemo {
public static void main(String[] args)
{
String name
= "EXTENDED_FILTERING";
// Getting the constant
// of Locale.FilteringMode
System.out.println("Locale.FilteringMode"
+ " value of "
+ name + ": "
+ Locale.FilteringMode
.valueOf(name));
}
}
输出:
Locale.FilteringMode value of EXTENDED_FILTERING: EXTENDED_FILTERING
参考: https://docs.oracle.com/javase/9/docs/api/ Java/util/Locale.FilteringMode.html#valueOf-java.lang.String-