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


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


描述

這個java.util.Formatter.out()方法 返回輸出的目的地。

聲明

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

public Appendable out()

參數

NA

返回值

此方法返回輸出的目的地

異常

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

示例

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

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 the output
      System.out.println("" + formatter.out());
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果——

Hello World !
Hello World !

相關用法


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