Java Data Type Tutorial - Java StringBuilder .ensureCapacity ( int minimumCapacity)








Syntax

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

public void ensureCapacity(int minimumCapacity)

Example

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

public class Main {
  public static void main(String args[]) {
    StringBuilder sb = new StringBuilder();
    sb.ensureCapacity(100 ); /*  ww w.  ja v  a 2s  .  c om*/
    sb.append("java2s.com");
    System.out.println(sb.capacity());
    System.out.println(sb.length());
    System.out.println(sb.toString());
    
  }
}

Output: