介绍
A thread-safe, mutable sequence of characters.A string buffer is like a {String}, but can be modified.
示例
public class Test {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
sb.append("费哥");
sb.append("爱你");
System.out.println(sb.toString());
}
}
结构
源码
成员变量
/**
* The value is used for character storage.
*/
char[] value;
构造方法
/**
* Constructs a string builder with no characters in it and an
* initial capacity of 16 characters.
*/
public StringBuffer() {
super(16);
}
成员方法
/**
* Appends the specified string to this character sequence.
*/
public synchronized StringBuffer append(String str) {
super.append(str);
return this;
}