Java StringBuffer append()方法

java.lang.StringBuffer.append(double d) 方法追加double参数到序列的字符串表示形式。

1 语法

public StringBuffer append(double d)

2 参数

d : 此是double值。

3 返回值

该方法返回一个此对象引用。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java StringBuffer append()方法
 */
import java.lang.*;

public class StringBufferDemo {

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

    // appends the double argument as string to the string buffer
    buff.append(30.100000001d);
    // print the string buffer after appending
    System.out.println("After append = " + buff);
    
    buff = new StringBuffer("abcd ");
    System.out.println("buffer = " + buff);
    // appends the double argument as string to the string buffer
    buff.append(20.12d);
    // print the string buffer after appending
    System.out.println("After append = " + buff);
  }
}

输出结果为:

buffer = tuts
After append = tuts 30.100000001
buffer = abcd
After append = abcd 20.12

 

热门文章

优秀文章