Sets the current length to a new value. If the new length is larger than the current length, then the new characters at the end of this object will contain the char value of \u0000. @param length the new length of this StringBuffer. @exception IndexOutOfBoundsException
(int length)
| 538 | * @see #length |
| 539 | */ |
| 540 | public void setLength(int length) { |
| 541 | if (length < 0) { |
| 542 | throw new StringIndexOutOfBoundsException(length); |
| 543 | } |
| 544 | if (length > value.length) { |
| 545 | enlargeBuffer(length); |
| 546 | } else { |
| 547 | if (shared) { |
| 548 | char[] newData = new char[value.length]; |
| 549 | System.arraycopy(value, 0, newData, 0, count); |
| 550 | value = newData; |
| 551 | shared = false; |
| 552 | } else { |
| 553 | if (count < length) { |
| 554 | Arrays.fill(value, count, length, (char) 0); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | count = length; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Returns the String value of the subsequence from the {@code start} index |
nothing calls this directly
no test coverage detected