Java StringBuffer Capacity Example
Chapter:
String Handling
Last Updated:
27-05-2017 14:44:42 UTC
Program:
/* ............... START ............... */
public class JavaStringBufferCapacity {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("JavaScan.com ");
System.out.println("capacity = " + buff.capacity());
buff = new StringBuffer(" ");
System.out.println("capacity = " + buff.capacity());
}
}
/* ............... END ............... */
Output
capacity = 29
capacity = 17
Notes:
-
The java.lang.StringBuffer.capacity() method returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur.
Tags
StringBuffer Capacity, Java, String