Java中的append方法是什么?
java.lang.StringBuffer的append(charc)方法将char参数的字符串表示形式附加到此序列。参数将附加到此序列的内容中。该序列的长度增加1。
示例
import java.lang.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("tuts ");
System.out.println("buffer = " + buff);
//将char参数作为字符串追加到字符串缓冲区。
buff.append('A');
//之后打印字符串缓冲区
System.out.println("After append = " + buff);
buff = new StringBuffer("abcd ");
System.out.println("buffer = " + buff);
//将char参数作为字符串追加到字符串缓冲区。
buff.append('!');
//之后打印字符串缓冲区
System.out.println("After append = " + buff);
}
}输出结果
buffer = tuts After append = tuts A buffer = abcd After append = abcd !