Converts to a string representing the data in this string builder. A new String object is allocated and initialized to contain the character sequence currently represented by this string builder. This String is then returned. Subsequent changes to the string builder do not affect the contents of the
()
| 565 | * Implementation advice: This method can be coded so as to create a new String object without allocating new memory to hold a copy of the character sequence. Instead, the string can share the memory used by the string builder. Any subsequent operation that alters the content or capacity of the string builder must then make a copy of the internal builder at that time. This strategy is effective for reducing the amount of memory allocated by a string concatenation operation when it is implemented using a string builder. |
| 566 | */ |
| 567 | public java.lang.String toString(){ |
| 568 | if (count == 0) { |
| 569 | return ""; |
| 570 | } |
| 571 | // Optimize String sharing for more performance |
| 572 | /*int wasted = value.length - count; |
| 573 | if (wasted >= 256 |
| 574 | || (wasted >= INITIAL_CAPACITY && wasted >= (count >> 1))) { |
| 575 | return new String(value, 0, count); |
| 576 | } |
| 577 | shared = true;*/ |
| 578 | return new String(value, 0, count); |
| 579 | } |
| 580 | |
| 581 | |
| 582 | public void trimToSize() { |
no outgoing calls