Forums Register Login

Size of String Buffer

+Pie Number of slices to send: Send
Hi, I have a doubt regarding string buffer. The default size of string buffer is 16. If we go on adding the elements, then on exceeding the size, the capacity will get doubled. It should be 32. But the capacity() returns 34. How the size gets increased?
+Pie Number of slices to send: Send
Which constructor are you using?

Better yet include the code you are using....if you can.
1
+Pie Number of slices to send: Send
What makes you think the capacity should be doubled? For instance, if you look at the Javadocs for the ensureCapacity method:

The new capacity is the larger of:

- The minimumCapacity argument.
- Twice the old capacity, plus 2.


If that's the behaviour whenever the capacity is increased, it would explain what you saw.
+Pie Number of slices to send: Send
 

Jared Malcolm wrote:Which constructor are you using?

Better yet include the code you are using....if you can.



It has nothing to do anything with the constructor. Any way I am using StringBuffer().
+Pie Number of slices to send: Send
 

Matthew Brown wrote:What makes you think the capacity should be doubled? For instance, if you look at the Javadocs for the ensureCapacity method:

The new capacity is the larger of:

- The minimumCapacity argument.
- Twice the old capacity, plus 2.


If that's the behaviour whenever the capacity is increased, it would explain what you saw.



Thank you sir, I got the clarity
I will open the floodgates of his own worst nightmare! All in a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2908 times.
Similar Threads
capacity of a stringbuffer
StringBuffer length
question about StringBuffer
StringBuffer
Subtring extraction
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:52:07.