Locale locale()
描述 (Description)
java.util.Formatter.locale()方法返回由此格式化程序的构造设置的语言环境。 具有locale参数的此对象的format方法不会更改此值。
声明 (Declaration)
以下是java.util.Formatter.locale()方法的声明public Locale locale()
参数 (Parameters)
NA
返回值 (Return Value)
如果未应用本地化,则此方法返回null,否则返回区域设置
异常 (Exception)
FormatterClosedException - 如果已通过调用其close()方法关闭此formatter
例子 (Example)
以下示例显示了java.util.Formatter.locale()方法的用法。package com.iowiki;
import java.util.Formatter;
import java.util.Locale;
public class FormatterDemo {
public static void main(String[] args) {
// create a new formatter
StringBuffer buffer = new StringBuffer();
Formatter formatter = new Formatter(buffer, Locale.US);
// format a new string
String name = "World";
formatter.format("Hello %s !", name);
// print the formatted string with default locale
System.out.println("" + formatter);
// print locale
System.out.println("" + formatter.locale());
}
}
让我们编译并运行上面的程序,这将产生以下结果 -Hello World !
en_US