Home »
Java programming language
Java Locale toString() Method with Example
Locale Class toString() method: Here, we are going to learn about the toString() method of Locale Class with its syntax and example.
Submitted by Preeti Jain, on March 08, 2020
Locale Class toString() method
- toString() method is available in java.util package.
- toString() method is for string denotation of this Locale along with country, language and variant code separated by an underscore.
- toString() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
- toString() method may throw an exception at the time of string denotation of this Locale.
Syntax:
public final String toString();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of the method is String, represents country, language and variant in the form of string.
Example:
// Java program to demonstrate the example
// of String toString() method of Locale
import java.util.*;
public class ToStringOfLocale {
public static void main(String[] args) {
// Instantiates Locale
Locale lo = new Locale("jap", "JAPAN", "AM");
// Display Locale
System.out.println("lo: " + lo);
// By using toString() method is
// to represent this locale as a String
System.out.println("lo.toString(): " + lo.toString());
}
}
Output
lo: jap_JAPAN_AM
lo.toString(): jap_JAPAN_AM