StringBuffer.ensureCapacity(int minimumCapacity) has the following syntax.
public void ensureCapacity(int minimumCapacity)
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. ja v a 2s . com sb.append("java2s.com"); System.out.println(sb.capacity()); System.out.println(sb.length()); System.out.println(sb.toString()); } }
Output: