}
这个方法是确保value数组长度够用的方法,调用的是父类的方法,此处不再赘述。
public synchronized void trimToSize() {
super.trimToSize();
}
这个方法是将value中多余的部分去掉的方法,调用的是父类的方法,此处不再赘述。
public synchronized void setLength(int newLength) {
toStringCache = null;
super.setLength(newLength);
}
这个方法是设定value长度的方法,调用的是父类的方法,此处不再赘述。
public synchronized char charAt(int index) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
return value[index];
}
这个方法返回指定下标的元素。
public synchronized int codePointAt(int index) {
return super.codePointAt(index);
}
public synchronized int codePointBefore(int index) {
return super.codePointBefore(index);
}
public synchronized int codePointCount(int beginIndex, int endIndex) {
return super.codePointCount(beginIndex, endIndex);
}
public synchronized int offsetByCodePoints(int index, int codePointOffset) {
return super.offsetByCodePoints(index, codePointOffset);
}
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
int dstBegin)
{
super.getChars(srcBegin, srcEnd, dst, dstBegin);
}
这些方法都是调用父类方法,此处不再赘述。
public synchronized void setCharAt(int index, char ch) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
toStringCache = null;
value[index] = ch;
}
这个方法是将指定下标的元素设为第二个参数,同时将缓存数组设为空。
public synchronized StringBuffer append(Object obj) {
toStringCache = null;
super.append(String.valueOf(obj));
return this;
}
public synchronized StringBuffer append(String str) {
toStringCache = null;
super.append(str);
return this;
}
public synchronized StringBuffer append(StringBuffer sb) {
toStringCache = null;
super.append(sb);
return this;
}
synchronized StringBuffer append(AbstractStringBuilder asb) {
toStringCache = null;
super.append(asb);
return this;
}
public synchronized StringBuffer append(CharSequence s) {
toStringCache = null;
super.append(s);
return this;
}
public synchronized StringBuffer append(CharSequence s, int start, int end)
{
toStringCache = null;
super.append(s, start, end);
return this;
}
public synchronized StringBuffer append(char[] str) {
toStringCache = null;
super.append(str);
return this;
}
public synchronized StringBuffer append(char[] str, int offset, int len) {
toStringCache = null;
super.append(str, offset, len);
return this;
}
public synchronized StringBuffer append(boolean b) {
toStringCache = null;
super.append(b);
return this;
}
public synchronized StringBuffer append(char c) {
toStringCache = null;
super.append(c);
return this;
}
public synchronized StringBuffer append(int i) {
toStringCache = null;
super.append(i);
return this;
}
public synchronized StringBuffer appendCodePoint(int codePoint) {
toStringCache = null;
super.appendCodePoint(codePoint);
return this;
}
public synchronized StringBuffer append(long lng) {
toStringCache = null;
super.append(lng);
return this;
}
public synchronized StringBuffer append(float f) {
toStringCache = null;
super.append(f);
return this;
}
public synchronized StringBuffer append(double d) {
toStringCache = null;
super.append(d);
return this;
}
这些方法调用的是父类的方法去拼接字符串,同时将缓存数组设为空,最后返回本对象。