![]() |
VOOZH | about |
The ensureCapacity() method of the StringBuffer class ensures that the buffer has at least the specified minimum capacity. This helps improve performance by reducing the number of internal memory reallocations when appending data.
Syntax:
public void ensureCapacity(int minimumCapacity)
Example 1: Default StringBuffer Capacity
Before ensureCapacity method capacity = 16 After ensureCapacity method capacity = 34
Explanation
Example 2: StringBuffer with Initial Content
Before ensureCapacity method capacity = 31 After ensureCapacity method capacity = 64
Explanation