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 ); /*from w w w .ja v a2 s. c o m*/
sb.append("java2s.com");
System.out.println(sb.capacity());
System.out.println(sb.length());
System.out.println(sb.toString());
}
}
Output: