Java Utility Library

Java Locale - getDisplayVariant() Method



The java.util.Locale.getDisplayVariant() method returns a name for the locale's variant code that is appropriate for display to the user. If possible, the name will be localized for the default DISPLAY locale. If the locale doesn't specify a variant code, this function returns the empty string.

Syntax

public final String getDisplayVariant()

Parameters

No parameter is required.

Return Value

Returns the name of the display variant code appropriate to the locale.

Exception

NA

Example:

In the example below, the java.util.Locale.getDisplayVariant() method is used to get the name of the variant of a 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 name of the variant
    System.out.println("Variant is: " + loc.getDisplayVariant());
  }
}

The output of the above code will be:

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

❮ Java.util - Locale