string buffer capacity

when i run this code the output is that the string buffer capacity is 17 and then after the for loop finishes it's capacity is 36. i know that the capacity changes as the object increases, but i was wondering why it's capacity starts off at 17 and ends at 36.

thanks

class StringBuffer{

static String dupl(String s,int times){

StringBuffer result =new StringBuffer(s);

System.out.println("result.capacity() = "+result.capacity());//17

for (int i=1; i<times; i++){

result.append(s);

}

System.out.println("result.capacity() = "+result.capacity());//36

return result.toString();

}

publicstaticvoid main(String[] args){

System.out.println(dupl("b",20));

}

}

>

[1448 byte] By [mark_8206a] at [2007-11-27 11:17:34]
# 1

Think about it, what is a buffer?

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html#StringBuffer()

_helloWorld_a at 2007-7-29 14:25:44 > top of Java-index,Java Essentials,New To Java...
# 2

> Think about it, what is a buffer?

>

> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Stri

> ngBuffer.html#StringBuffer()

thanks i never knew it has an initial capacity of 16 characters

mark_8206a at 2007-7-29 14:25:44 > top of Java-index,Java Essentials,New To Java...