php    php100   android
當前位置:首頁 » java.lang包 »

Java.lang.StringBuffer.toString()方法實例

評論  編輯

描述

The java.lang.StringBuffer.toString() method returns a string representing the data in this sequence.
A new String object is allocated and initialized to contain the character sequence currently represented by this object. This String is then returned.

聲明

Following is the declaration for java.lang.StringBuffer.toString() method

public String toString()

參數

  • NA

返回值

This method returns a string representation of this sequence of characters.

異常

  • NA

實例一

編輯 +分享實例

以下例子將告訴你如何使用 java.lang.StringBuffer.toString() method.

package gitbook.net;

import java.lang.*;

public class StringBufferDemo {
 
  public static void main(String[] args) {
  
    StringBuffer buff = new StringBuffer("India ");
    System.out.println("buffer = " + buff);

    // append character to the stringbuffer
    buff.append('!');
    // convert to string object and print it
    System.out.println("After append = " + buff.toString());
      
    buff = new StringBuffer("Hi "); 
    System.out.println("buffer = " + buff);
    // append integer to the stringbuffer
    buff.append(123);
    // convert to string object and print it
    System.out.println("After append = " + buff.toString());
  }
}

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

buffer = India
After append = India !
buffer = Hi
After append = Hi 123

貢獻/合作者

正在開放中...
 

評論(條)

  • 還冇有評論!