Locale getDisplayVariant() in Java

getDisplayVariant(): This method is available in java.util.Locale class of Java.

Syntax:

String java.util.Locale.getDisplayVariant()

This method returns a name for the locale's variant code that is appropriate for display to the user.

Note: If the locale doesn't specify a variant code, this function returns the empty string.

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

For Example:

Locale locale = new Locale("en", "USA", "US")

locale.getDisplayVariant() = > It returns US.

Approach

Java

import java.util.Locale;

public class LocalegetDisplayVariant {

    public static void main(String[] args) {

        Locale locale = new Locale("en""USA""US");

        System.out.println(locale.getDisplayVariant());
    }
}

Output:

US

No comments:

Post a Comment