Share via


StringBuffer.setLength

Class Overview | Class Members | This Package | All Packages

Syntax

public synchronized void setLength( int newLength )

Parameters
  • newLength
    the new length of the buffer.
Description

Sets the length of this String buffer. If the newLength argument is less than the current length of the string buffer, the string buffer is truncated to contain exactly the number of characters given by the newLength argument.

If the newLength argument is greater than or equal to the current length, sufficient null characters ('\u0000') are appended to the string buffer so that length becomes the newLength argument.

The newLength argument must be greater than or equal to 0.

Exceptions

StringIndexOutOfBoundsException if the newLength argument is invalid.

See Also

length