Java StringBuffer ensureCapacity Example
StringBuffer class ensureCapacity method example. This example shows you how to use ensureCapacity method.
StringBuffer class ensureCapacity method example. This example shows you how to use ensureCapacity method.
Ensures that the capacity is at least equal to the specified minimum. If the current capacity is less than the argument, then a new internal array is allocated with greater capacity. The new capacity is the larger of:
Here is the full code
/**
* @(#) EnsureCapacity. java
* A class representing ensureCapacity method
* @Version 01-May-2008
* @author Rose India Team
*/
public class EnsureCapacity {
public static void main(String args[]) {
StringBuffer sb = new StringBuffer("Rose India");
//Returns the current capacity of the String buffer.
System.out.println("Buffer : "+sb+"\nCapacity : " + sb.capacity());
//Increases the capacity, as needed, to the specified amount in the given string buffer object
sb.ensureCapacity(27);
System.out.println("New Capacity = " + sb.capacity());
}
} |
null
|