Formatter类的locale()方法 (Formatter Class locale() method)
locale() method is available in java.util package.
locale()方法在java.util包中可用。
locale() method is used to returns the locales assign by the construction of this Formatter.
locale()方法用于返回通过此Formatter的构造分配的语言环境。
locale() 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.
locale()方法是一种非静态方法,可通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
locale() method may throw an exception at the time of returning Locale object.
返回Locale对象时, locale()方法可能会引发异常。
FormatterClosedException: This exception may throw when this Formatter close by calling it's close().
FormatterClosedException:当此Formatter通过调用close()关闭时,可能会引发此异常。
Syntax:
句法:
public Locale locale();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is Locale, it returns locale of this formatter otherwise it returns null.
此方法的返回类型为Locale ,它返回此格式化程序的语言环境,否则返回null。
Example:
例:
// Java program is to demonstrate the example of
// locale() method of Formatter
import java.util.*;
public class LocaleOfFormatter {
public static void main(String[] args) {
// Instantiates a StringBuffer and Formmatter object
StringBuffer sb = new StringBuffer();
Formatter formatt = new Formatter(sb, Locale.UK);
// By using format() method is to format a string
formatt.format("Hi %s !", "IncludeHelp");
// Display Formatted String
System.out.println(formatt);
// By using locale() method is to
// return the locale set by the formation
// of this Formattr
System.out.println("formatt.locale(): " + formatt.locale());
}
}
Output
输出量
Hi IncludeHelp !
formatt.locale(): en_GB
翻译自: https://www.includehelp.com/java/formatter-locale-method-with-example.aspx