Locale getLanguage() in Java

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

Syntax:

String java.util.Locale.getLanguage()

This method returns the language code of this Locale.

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

For Example:

Locale locale = new Locale("en", "IN")

locale.getLanguage() = > It returns en.

Approach

Java

import java.util.Locale;

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

        Locale locale = new Locale("en""IN");

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

Output:

en

No comments:

Post a Comment