Java中的Locale类的getVariant()方法用于获取指定语言环境的变体代码。如果未指定任何内容,则返回一个空字符串
用法:
LOCALE.getLanguage()
参数:此方法不带任何参数。
返回值:此方法返回空字符串或给定语言环境的变体代码。
以下示例程序旨在说明getVariant()方法的用法:
示例1:
// Java code to illustrate getVariant() method
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
// Creating a new locale
Locale first_locale
= new Locale("nu", "NO", "NY");
// Displaying first locale
System.out.println("First Locale: "
+ first_locale);
// Displaying the variant_code of this locale
System.out.println("Variant: "
+ first_locale.getVariant());
}
}
输出:
First Locale: nu_NO_NY
Variant: NY
示例2:
// Java code to illustrate getVariant() method
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
// Creating a new locale
Locale first_locale
= new Locale("ar", "SA");
// Displaying first locale
System.out.println("First Locale: "
+ first_locale);
// Displaying the variant_code of this locale
System.out.println("Variant: "
+ first_locale.getVariant());
}
}
输出:
First Locale: ar_SA
Variant: