62,614
社区成员
发帖
与我相关
我的任务
分享
/* public final class StringBuffer
extends AbstractStringBuilder
implements java.io.Serializable, CharSequence类中
*/
public synchronized StringBuffer append(String str) {
super.append(str);////
return this;
}
/////////abstract class AbstractStringBuilder中
public AbstractStringBuilder append(String str) {
if (str == null) str = "null";
int len = str.length();
if (len == 0) return this;
int newCount = count + len;
if (newCount > value.length)
expandCapacity(newCount);/////////////
str.getChars(0, len, value, count);
count = newCount;
return this;
}
void expandCapacity(int minimumCapacity) {
int newCapacity = (value.length + 1) * 2;/////////这里(5+1)*2=12
if (newCapacity < 0) {
newCapacity = Integer.MAX_VALUE;
} else if (minimumCapacity > newCapacity) {
newCapacity = minimumCapacity;
}
value = Arrays.copyOf(value, newCapacity);
}