| Author |
StringBuffer capacity
|
Alvin chew
Ranch Hand
Joined: Jan 08, 2004
Posts: 834
|
|
hi, good day everyone here , i get confuse on the capacity of stringbuffer, if my stringbuffer content is : a*b*c*d*e* when i use capacity method to check the capacity of my stringbuffer, why is it so my capacity is 16 ? thank you very much for help for your info : i using following code to get the stringbuffer and have been call 5 times by parameter a,b,c,d,e
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
A StringBuffer has an array member that it uses to hold the characters, and an int that tells how many of the array positions are actually valid. The rest of the array contains zeroes, or garbage. In general, the size of the array (the capacity) won't be equal to the number of characters in the StringBuffer (the size). It's quite inefficient to try to keep the array exactly the right size; to do so, StringBuffer would have to allocate a new array every time you called append. By keeping some extra empty space, StringBuffer can only reallocate the array once in a while.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: StringBuffer capacity
|
|
|