Java StringBuffer append()方法

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

1 语法

public StringBuffer append(boolean b)

2 参数

b : 这是布尔值。

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 boolean argument as string to the string buffer
    buff.append(true);
    // print the string buffer after appending
    System.out.println("After append = " + buff);
    
    buff = new StringBuffer("abcd ");
    System.out.println("buffer = " + buff);
    // appends the boolean argument as string to the string buffer    
    buff.append(false);
    // print the string buffer after appending
    System.out.println("After append = " + buff);
  }
}

输出结果为:

buffer = tuts
After append = tuts true
buffer = abcd
After append = abcd false

 

热门文章

优秀文章