java.util.Formatter.locale() 方法返回locale这个格式化的构造设置。该格式的方法为这个对象,它有一个locale参数但不会改变这个值。
声明
以下是java.util.Formatter.locale()方法的声明
public Locale locale()
参数
-
NA
返回值
如果没有本地化应用此方法返回null,否则为语言环境
异常
-
FormatterClosedException -- 如果该格式已经被关闭通过调用它的close()方法
例子
下面的示例演示java.util.Formatter.locale()方法的用法。
package com.yiibai; 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