Java Locale - toString() Method
The java.util.Locale.toString() method returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below:
language + "_" + country + "_" + (variant + "_#" | "#") + script + "-" + extensions
Language is always lower case, country is always upper case, script is always title case, and extensions are always lower case.
Syntax
public final String toString()
Parameters
No parameter is required.
Return Value
Returns a string representation of the Locale, for debugging.
Exception
NA
Example:
In the example below, the java.util.Locale.toString() method is used to get a string representation of the given Locale object.
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); //creating a string representation of the locale String locString = loc.toString(); //printing the string representation of the locale System.out.println("locString is: " + loc.toString()); } }
The output of the above code will be:
loc is: th_TH_TH_#u-nu-thai locString is: th_TH_TH_#u-nu-thai
❮ Java.util - Locale