php    php100   android
當前位置:首頁 » Java.util包 »

Java.util.Formatter.format(Locale l,String format,Object... args)方法實例

評論  編輯

描述

The java.util.Formatter.format(Locale l,String format,Object... args) method writes a formatted string to this object's destination using the specified locale, format string, and arguments.

聲明

Following is the declaration for java.util.Formatter.format() method

public Formatter format(Locale l,String format,Object... args)

參數

  • l -- The locale to apply during formatting. If l is null then no localization is applied. This does not change this object's locale that was set during construction.

  • format -- A format string as described in Format string syntax.

  • args -- Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification

返回值

This method returns this formatter

異常

  • FormatterClosedException -- If this formatter has been closed by invoking its close() method

  • IllegalFormatException -- If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions.

實例一

編輯 +分享實例

以下例子將告訴你如何使用 java.util.Formatter.flush() method.

package gitbook.net;

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(Locale.US,"Hello %s !", name);

      // print the formatted string with specified locale
      System.out.println("" + formatter + " " + formatter.locale());

      
   }
}

編譯和執行以上程序,將得到以下的結果:

Hello World ! en_US

貢獻/合作者

正在開放中...
 

評論(條)

  • 還冇有評論!