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 inLocale. If the locale doesn't specify a variant code, this function returns the empty string.
Syntax
public String getDisplayVariant(Locale inLocale)
Parameters
inLocale |
Specify the locale for which to retrieve the display variant code. |
Return Value
Returns the name of the display variant code appropriate to the given locale.
Exception
Throws NullPointerException, if inLocale is null.
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 //based on specified inLocale System.out.println("Variant is: " + loc.getDisplayVariant(Locale.GERMANY)); } }
The output of the above code will be:
loc is: th_TH_TH_#u-nu-thai Variant is: TH
❮ Java.util - Locale