This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes capacity  of a stringbuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "capacity  of a stringbuffer" Watch "capacity  of a stringbuffer" New topic
Author

capacity of a stringbuffer

Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163


Hi,
I didn't understand Line4 & Line6 in the output. Can any one explain me pls.
Mylene Reiners
Greenhorn

Joined: Apr 08, 2004
Posts: 7
Every string buffer has a capacity. As long as the length of the character sequence contained in the string buffer does not exceed the capacity, it is not necessary to allocate a new internal buffer array. If the internal buffer overflows, it is automatically made larger.

AFAIK there is no specific size give to enlarge it with, so it is decided by the VM... (when you google, you'll find figures like 16 bits, but it doesn't seem to be right).
Chintamani Kashalikar
Greenhorn

Joined: Jan 03, 2006
Posts: 1
When append method is called on a StringBuffer, first it checks for the available capacity (capacity() - length()) of the StringBuffer. If available capacity is less less than the length of string (or whatever you are appending). The capacity of the StringBuffer is increased. The new capacity is the larger of:

1. The length of string being appended.
2. Twice the old capacity, plus 2.

(Similar to ensureCapacity method of StringBuffer).


Cheers...........Chints
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Thanq Chints
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: capacity of a stringbuffer
 
It's not a secret anymore!