Java Locale - getLanguage() Method
The java.util.Locale.getLanguage() method returns the language code of this Locale.
Syntax
public String getLanguage()
Parameters
No parameter is required.
Return Value
Returns the language code, or the empty string if none is defined.
Exception
NA
Example:
In the example below, the java.util.Locale.getLanguage() method is used to get the language code of the given Locale.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a locale Locale loc = new Locale("EN", "UK"); //printing the locale System.out.println("loc is: " + loc); //printing the language code System.out.println("Language Code is: " + loc.getLanguage()); } }
The output of the above code will be:
loc is: en_UK Language Code is: en
❮ Java.util - Locale