Locale getVariant() in Java

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

Syntax:

String java.util.Locale.getVariant()

This method returns the variant code for this locale.

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

For Example:

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

locale.getVariant() = > It returns US.

Approach

Java

import java.util.Locale;

public class LocalegetVariant {
    public static void main(String[] args) {

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

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

Output:

US

No comments:

Post a Comment