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

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

Java的Locale getDisplayVariant() 方法和示例

JavaLocale 类getDisplayVariant()方法用于获取指定locale 中提到的locale 变体代码的名称,并适当地显示给用户。如果区域设置中未提及变体代码,则该函数返回一个空字符串。

句法:

LOCALE.getDisplayVariant()

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

返回值:此方法返回适合区域设置的显示变量代码的名称。

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



方案一:

// Java code to illustrate getDisplayVariant() method
  
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("th", "TH", "TH");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        // Displaying the variant code for locale
        System.out.println("Variant: "
                           + first_locale.getDisplayVariant());
    }
}
输出:
First Locale: th_TH_TH_#u-nu-thai
Variant: TH

方案二:

// Java code to illustrate getDisplayVariant() method
  
import java.util.*;
  
public class Locale_Demo {
    public static void main(String[] args)
    {
  
        // Creating a new locale
        Locale first_locale
            = new Locale("en", "IN");
  
        // Displaying first locale
        System.out.println("First Locale: "
                           + first_locale);
  
        // Displaying the variant code for locale
        System.out.println("Variant: "
                           + first_locale.getDisplayVariant());
    }
}
输出:
First Locale: en_IN
Variant: