當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.util.Formatter.locale()用法及代碼示例


描述

這個java.util.Formatter.locale()方法返回由此格式化程序的構造設置的語言環境。具有區域設置參數的此對象的格式方法不會更改此值。

聲明

以下是聲明java.util.Formatter.locale()方法

public Locale locale()

參數

NA

返回值

如果未應用本地化,則此方法返回 null,否則返回語言環境

異常

FormatterClosedExceptionâˆ' 如果此格式化程序已通過調用其 close() 方法關閉

示例

下麵的例子展示了 java.util.Formatter.locale() 方法的用法。

package com.tutorialspoint;

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

相關用法


注:本文由純淨天空篩選整理自 Java.util.Formatter.locale() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。