What is the capacity of a StringBuffer?

See: download.oracle.com/javase/6/docs/api/ja...) But your assumption is correct: "The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur".

Yes, you're correct, see the JavaDoc for more information: 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.

Internally StringBuffer uses a char array in order to store characters. Capacity is the initial size of that char array. More INFO can be found from download.oracle.com/javase/6/docs/api/ja....

From download.oracle.com/javase/6/docs/api/ja... public int capacity() Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur. Also from the same document As of release JDK 5, this class has been supplemented with an equivalent class designed for use by a single thread, StringBuilder.

The StringBuilder class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization.

Yes, it's exactly that. You can think of StringBuffer as being a bit like a Vector in that respect (except obviously you can't use char as a type argument in Java...).

Taken from the official J2SE documentation The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur. Its generally length+16.

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.

From: download.oracle.com/javase/1.4.2/docs/ap....

StringBuffer has a char in which it keeps the strings that you append to it. The amount of memory currently allocated to that buffer is the capacity. The amount currently used is the length.

It's the size of internal buffer. As Javadoc says: 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.

Ivan, just read the documentation for capacity() - it directly answers your question...

I already red it, and it says "capacity is the amount of storage" but I wasn't sure what is measure unit for this amount. As some approved this measure unit is "number of characters". Thanks.

– Иван Бишевац Nov 4 at 15:33 Quote: Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur. – DejanLekic Nov 4 at 17:43.

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."

download.oracle.com/javase/1.3/docs/api/... -see capacity() and ensurecapacity().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions