Java.util.Locale 类

java.util.Locale.getVariant() 方法返回此语言环境的变体代码。

语法

public String getVariant()

参数

不需要参数。

返回值

返回变体代码,如果没有定义,则为空字符串。

异常

示例:

在下面的示例中,java.util.Locale.getVariant() 方法用于获取给定 Locale 的变体代码。

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //创建语言环境
    Locale loc = new Locale("th", "TH", "TH");

    //打印语言环境
    System.out.println("loc is: " + loc);

    //打印变体代码
    System.out.println("Variant Code is: " + loc.getVariant());
  }
}

上述代码的输出将是:

loc is: th_TH_TH_#u-nu-thai
Variant Code is: TH