容量。它们的一般形式如下:
int length()
int capacity()
这里是一个例子:
//StringBuffer length vs.capacity.
class StringBufferDemo
{
public static void main(String args[])
{
StringBuffer sb = new StringBuffer("Hello");
看了楼上几个回复没一个是准确的。
length,返回当前已存字符长度没什么疑问。
capacity,方法说明如下:
Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur.
Overrides: capacity() in AbstractStringBuilder
Returns:
the current capacity