/**
* The value is used for character storage.
*/char[] value;
/**
* The count is the number of characters used.
*/int count;
构造方法
/**
* Constructs a string builder with no characters in it and an
* initial capacity of 16 characters.
*/// 默认构造方法,设置 char[] value 的长度,默认16publicStringBuilder() {
super(16);
}
/**
* Constructs a string builder with no characters in it and an
* initial capacity specified by the <code>capacity</code> argument.
*
* @param capacity the initial capacity.
* @throws NegativeArraySizeException if the <code>capacity</code>
* argument is less than <code>0</code>.
*/publicStringBuilder(int capacity) {
super(capacity);
}
/**
* Constructs a string builder initialized to the contents of the
* specified string. The initial capacity of the string builder is
* <code>16</code> plus the length of the string argument.
*
* @param str the initial contents of the buffer.
* @throws NullPointerException if <code>str</code> is <code>null</code>
*/// 构造参数为字符串,char[] value 的长度为字符串的长度+16publicStringBuilder(String str) {
super(str.length() + 16);
append(str);
}
/**
* Constructs a string builder that contains the same characters
* as the specified <code>CharSequence</code>. The initial capacity of
* the string builder is <code>16</code> plus the length of the
* <code>CharSequence</code> argument.
*
* @param seq the sequence to copy.
* @throws NullPointerException if <code>seq</code> is <code>null</code>
*/publicStringBuilder(CharSequence seq) {
this(seq.length() + 16);
append(seq);
}