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

贡献/合作者

正在开放中...
 

评论(条)

  • 还没有评论!