The locale() method is a built-in method of the java.util.Formatter which returns a locale. This locale is set by the formatter construction. The format method for this object which has a locale argument does not change this value.
public Locale locale()
Parameters: The function accepts no parameter.
Return Value: The function returns null if no localization is applied, otherwise a locale which has been initialized to the formatter.
Exceptions: The function throws FormatterClosedException if the formatter has been closed before the function call.
Below is the implementation of the above function:
What is your name? My name is Gopal Dave ! Locale: en_CA
What is your name? My name is Gopal Dave ! Exception is: java.util.FormatterClosedException
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.