jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes StringBuffer capacity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "StringBuffer capacity" Watch "StringBuffer capacity" New topic
Author

StringBuffer capacity

Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522

1) on line 2, a string buffer (s) of capacity 16 + 5 = 21 is created.
2) on line 3, we appended ss to s making 16 + 5 = 21, which fits perfectly in s, making the output on line 4 equals to 21.
my question is: if we add another character to ss

the output (capcity) of s becomes 44 !!! isn't suppose that the capacity increases by one, hence becoming 22??


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
when using append() for a StringBuffer, the ensureCapacity() method is implicitly called. See JLS1 - StringBuffer
Miki


Miki<br /> <br />SCJP 1.4, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringBuffer capacity
 
Similar Threads
StringBuffer
How many String objects created?
StringBuffer
Doubt of String Buffer for Vicken Karaoghlanian & others
What's special about StringBuffer ?