首页 > 代码库 > StringBuffer类
StringBuffer类
void
getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
将字符从此字符串复制到目标字符数组。
//不能被继承
public final class StringBuffer
extends AbstractStringBuilder
implements java.io.Serializable, CharSequence{}
StringBuffer类继承AbstractStringBuilder,AbstractStringBuilder中有两个属性:
/** * The value is used for character storage. */ char[] value; /** * The count is the number of characters used. */ int count;
几个重要的方法:
1 public AbstractStringBuilder append(String str) {2 if (str == null) str = "null";3 int len = str.length();4 ensureCapacityInternal(count + len);5 str.getChars(0, len, value, count);6 count += len;7 return this;8 }
private void ensureCapacityInternal(int minimumCapacity) { // overflow-conscious code if (minimumCapacity - value.length > 0) expandCapacity(minimumCapacity); }
void expandCapacity(int minimumCapacity) { int newCapacity = value.length * 2 + 2; if (newCapacity - minimumCapacity < 0) newCapacity = minimumCapacity; if (newCapacity < 0) { if (minimumCapacity < 0) // overflow throw new OutOfMemoryError(); newCapacity = Integer.MAX_VALUE; } value = Arrays.copyOf(value, newCapacity); }
StringBuffer类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。