📌  相关文章
📜  Java的Locale getVariant() 方法和示例

📅  最后修改于: 2022-05-13 01:57:13.126000             🧑  作者: Mango

Java的Locale getVariant() 方法和示例

JavaLocale 类getVariant()方法用于获取指定语言环境的变体代码。如果未指定任何内容,则返回空字符串

句法:

LOCALE.getLanguage()

参数:该方法不带任何参数。

返回值:此方法返回空字符串或给定语言环境的变体代码。

下面的程序说明了 getVariant() 方法的工作:



方案一:

// 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

方案二:

// 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: