72 |
* @since 1.0 |
* @since 1.0 |
73 |
* @status updated to 1.4 |
* @status updated to 1.4 |
74 |
*/ |
*/ |
75 |
public final class StringBuffer implements Serializable, CharSequence |
public final class StringBuffer |
76 |
|
implements Serializable, CharSequence, Appendable |
77 |
{ |
{ |
78 |
/** |
/** |
79 |
* Compatible with JDK 1.0+. |
* Compatible with JDK 1.0+. |
149 |
} |
} |
150 |
|
|
151 |
/** |
/** |
152 |
|
* Create a new <code>StringBuffer</code> with the characters in the |
153 |
|
* specified <code>CharSequence</code>. Initial capacity will be the |
154 |
|
* length of the sequence plus 16; if the sequence reports a length |
155 |
|
* less than or equal to 0, then the initial capacity will be 16. |
156 |
|
* |
157 |
|
* @param seq the initializing <code>CharSequence</code> |
158 |
|
* @throws NullPointerException if str is null |
159 |
|
* @since 1.5 |
160 |
|
*/ |
161 |
|
public StringBuffer(CharSequence seq) |
162 |
|
{ |
163 |
|
int len = seq.length(); |
164 |
|
count = len <= 0 ? 0 : len; |
165 |
|
value = new char[count + DEFAULT_CAPACITY]; |
166 |
|
for (int i = 0; i < len; ++i) |
167 |
|
value[i] = seq.charAt(i); |
168 |
|
} |
169 |
|
|
170 |
|
/** |
171 |
* Get the length of the <code>String</code> this <code>StringBuffer</code> |
* Get the length of the <code>String</code> this <code>StringBuffer</code> |
172 |
* would create. Not to be confused with the <em>capacity</em> of the |
* would create. Not to be confused with the <em>capacity</em> of the |
173 |
* <code>StringBuffer</code>. |
* <code>StringBuffer</code>. |
426 |
return this; |
return this; |
427 |
} |
} |
428 |
|
|
429 |
|
/** |
430 |
|
* Append the characters in the <code>CharSequence</code> to this |
431 |
|
* buffer. |
432 |
|
* |
433 |
|
* @param seq the <code>CharSequence</code> providing the characters |
434 |
|
* @return this <code>StringBuffer</code> |
435 |
|
* @since 1.5 |
436 |
|
*/ |
437 |
|
public synchronized StringBuffer append(CharSequence seq) |
438 |
|
{ |
439 |
|
return append(seq, 0, seq.length()); |
440 |
|
} |
441 |
|
|
442 |
|
/** |
443 |
|
* Append some characters from the <code>CharSequence</code> to this |
444 |
|
* buffer. If the argument is null, the four characters "null" are |
445 |
|
* appended. |
446 |
|
* |
447 |
|
* @param seq the <code>CharSequence</code> providing the characters |
448 |
|
* @param start the starting index |
449 |
|
* @param end one past the final index |
450 |
|
* @return this <code>StringBuffer</code> |
451 |
|
* @since 1.5 |
452 |
|
*/ |
453 |
|
public synchronized StringBuffer append(CharSequence seq, int start, int end) |
454 |
|
{ |
455 |
|
if (seq == null) |
456 |
|
return append("null"); |
457 |
|
if (end - start > 0) |
458 |
|
{ |
459 |
|
ensureCapacity_unsynchronized(count + end - start); |
460 |
|
for (; start < end; ++start) |
461 |
|
value[count++] = seq.charAt(start); |
462 |
|
} |
463 |
|
return this; |
464 |
|
} |
465 |
|
|
466 |
/** |
/** |
467 |
* Append the <code>String</code> value of the argument to this |
* Append the <code>String</code> value of the argument to this |
468 |
* <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert |
* <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert |