java 方法 示例
区域设置类getDisplayVariant()方法 (Locale Class getDisplayVariant() method)
Syntax:
句法:
public final String getDisplayVariant();public String getDisplayVariant(Locale lo);
getDisplayVariant() method is available in java.util package.
getDisplayVariant()方法在java.util包中可用。
getDisplayVariant() method is used to display name for the locale variant and the displayed name will be localized as per based on the default locale.
getDisplayVariant()方法用于显示语言环境变体的名称,并且将根据默认语言环境对显示的名称进行本地化。
getDisplayVariant(Locale lo) method is used to display name for the locale variant and the displayed name will be localized as per based on the given locale (lo).
getDisplayVariant(Locale lo)方法用于显示语言环境变体的名称,并且显示的名称将根据给定的语言环境(lo)进行本地化。
These methods may throw an exception at the time of displaying a variant of the locale.
这些方法在显示语言环境的变体时可能会引发异常。
NullPointerException: This exception may throw when the given parameter is null exists.
NullPointerException :当给定参数为null时,可能引发此异常。
These are non-static methods and it is accessible with the class object and if we try to access these methods with the class name then also we will get an error.
这些是非静态方法,可通过类对象访问,如果尝试使用类名访问这些方法,则也会收到错误消息。
Parameter(s):
参数:
In the first case, getDisplayVariant() – It does not accept any parameter.
在第一种情况下, getDisplayVariant() –不接受任何参数。
In the second case, getDisplayVariant(Locale lo)
在第二种情况下, getDisplayVariant(Locale lo)
Locale lo – represents the locale.
语言环境lo –表示语言环境。
Return value:
返回值:
In both the cases, the return type of the method is String – it displays variant for the locale but does not return any value.
在这两种情况下,方法的返回类型均为String -它显示语言环境的变体,但不返回任何值。
Example:
例:
// Java program to demonstrate the example
// of getDisplayVariant() method of Locale
import java.util.*;
public class GetDisplayVariantOfLocale {
public static void main(String[] args) {
// Instantiates Locale
Locale lo1 = new Locale("JAPANESE", "JAPAN", "JAP");
Locale lo2 = new Locale("FRENCH", "FRANCE", "FRA");
// Display Locale
System.out.println("lo1: " + lo1);
System.out.println("lo2: " + lo2);
// By using getDisplayVariant() method is
// to return the name for this locale variant
String var1 = lo1.getDisplayVariant();
System.out.println("lo1.getDisplayVariant(): " + var1);
// By using getDisplayVariant(locale) method is
// to return the name for this locale variant will
// be localized by the given locale
String var2 = lo1.getDisplayVariant(lo2);
System.out.println("lo1.getDisplayVariant(lo2): " + var2);
}
}
Output
输出量
lo1: japanese_JAPAN_JAP
lo2: french_FRANCE_FRA
lo1.getDisplayVariant(): JAP
lo1.getDisplayVariant(lo2): JAP
翻译自: https://www.includehelp.com/java/locale-getdisplayvariant-method-with-example.aspx
java 方法 示例