Java Utility Library

Java Locale - getVariant() Method



The java.util.Locale.getVariant() method returns the variant code for this locale.

Syntax

public String getVariant()

Parameters

No parameter is required.

Return Value

Returns the variant code, or the empty string if none is defined.

Exception

NA

Example:

In the example below, the java.util.Locale.getVariant() method is used to get the variant code of the given Locale.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a locale
    Locale loc = new Locale("th", "TH", "TH");

    //printing the locale
    System.out.println("loc is: " + loc);

    //printing the variant code
    System.out.println("Variant Code is: " + loc.getVariant());
  }
}

The output of the above code will be:

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

❮ Java.util - Locale