哪位高手能给我解释一下这个Java程序的运行结果?
hrwlw 2007-09-05 02:52:24 Java源程序如下:
import java.io.*;
public class capacity
{
public static void main(String[] args)
{
StringBuffer buffer = new StringBuffer("Hello,how are you?");
String output= "buffer="+buffer.toString()+"\nlength="+buffer.length()+"\ncapacity="+buffer.capacity();
buffer.ensureCapacity(69);
output+= "\n\nNew capacity="+buffer.capacity();
buffer.setLength(10);
output+= "\n\nNew length="+buffer.length()+"\nbuffer="+buffer;
System.out.println(output);
}
}
程序运行结果如下:
buffer=Hello,how are you?
length=18
capacity=34
New capacity=70
New length=10
buffer=Hello,how
其中length=18,New length=10明白,capacity=34和New capacity=70是怎么算的?
请多多指教,谢谢!