Java StringBuilder append()方法

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

1 语法

public StringBuilder append(float f)

2 参数

f : 这是float值。

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 float argument as string to the StringBuilder
    str.append(9.1f);
    // print the StringBuilder after appending
    System.out.println("After append = " + str);
    
    str = new StringBuilder("abcd ");
    System.out.println("string = " + str);
    // appends the float argument as string to the StringBuilder
    str.append(33.28f);
    // print the StringBuilder after appending
    System.out.println("After append = " + str);
  }
}

输出结果为:

string = tuts
After append = tuts 9.1
string = abcd
After append = abcd 33.28

 

热门文章

优秀文章