Java StringBuilder append()方法

java.lang.StringBuilder.append(boolean b) 方法追加布尔参数到序列的字符串表示形式。

1 语法

public StringBuilder append(boolean b)

2 参数

b : 这是布尔值。

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("compile ");
    System.out.println("string = " + str);

    // appends the boolean argument as string to the StringBuilder
    str.append(true);
    // print the StringBuilder after appending
    System.out.println("After append = " + str);
    
    str = new StringBuilder("abcd ");
    System.out.println("string = " + str);
    // appends the boolean argument as string to the String Builder    
    str.append(false);
    // print the string Builder after appending
    System.out.println("After append = " + str);
  }
}

输出结果为:

string = compile
After append = compile true
string = abcd
After append = abcd false

 

热门文章

优秀文章