介绍
A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization.
示例
public class Test {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
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 StringBuilder() {
super(16);
}
成员方法
/**
* Appends the specified string to this character sequence.
*/
public StringBuilder append(String str) {
super.append(str);
return this;
}