Java StringBuilder append()方法

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

1 语法

public StringBuilder append(double d)

2 参数

d : 这是double值。

3 返回值

该方法返回这个对象的引用。

4 示例 

package com.yiidian;

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

public class StringBuilderDemo {

  public static void main(String[] args) {
  
    StringBuilder str = new StringBuilder("tuts ");
    System.out.println("string = " + str);

    // appends the double argument as string to the StringBuilder
    str.append(30.100000001d);
    // print the StringBuilder after appending
    System.out.println("After append = " + str);
    
    str = new StringBuilder("abcd ");
    System.out.println("string = " + str);
    // appends the double argument as string to the StringBuilder
    str.append(15.12d);
    // print the string Builder after appending
    System.out.println("After append = " + str);
  }
}

输出结果为:

string = tuts
After append = tuts 30.100000001
string = abcd
After append = abcd 15.12

 

热门文章

优秀文章