Java StringBuffer append()方法

java.lang.StringBuffer.append(char c) 方法追加char参数,以这个序列的字符串表示形式。该参数被附加到这个序列中。此序列的长度增加1。

1 语法

public StringBuffer append(char c)

2 参数

c : 这是char值。

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

输出结果为:

buffer = tuts
After append = tuts A
buffer = abcd
After append = abcd !

 

热门文章

优秀文章