Java StringBuffer .ensureCapacity ( int minimumCapacity)

Syntax

StringBuffer.ensureCapacity(int minimumCapacity) has the following syntax.

public void ensureCapacity(int minimumCapacity)

Example

In the following code shows how to use StringBuffer.ensureCapacity(int minimumCapacity) method.


public class Main {
  public static void main(String args[]) {
    StringBuffer sb = new StringBuffer();
    sb.ensureCapacity(100 ); /*  w w  w  .  j  ava  2 s .  c o m*/
    sb.append("java2s.com");
    System.out.println(sb.capacity());
    System.out.println(sb.length());
    System.out.println(sb.toString());
    
  }
}

Output:





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable