0
calculation for capacity
StringBuffer sbl = new StringBuffer ("Capacity of sb"); System.out.println(sbl.capacity ()); OUTPUT IS 30 capacity of sbl = 14 initial memory allocated = 16 my question is how does the java calculated the capacity?
2 Respostas
+ 1
public StringBuffer (String str) constructs a string buffer initialized to the specified string. The inicial capacity of the StringBuffer is 16 plus the lenght of the string argumento.
The capacity is the amount of storage avaliable for newly inserted characters, beyond which an allocation will occur.
Every string buffer has a capacity. As long as The lenght of the characters sequence contained in the string buffer does not exceed the capacity, it is not necessary to allocate a new internal buffer array. If internal buffer overflows, it automatically made larger.
0
Thanks for the answer. excuse me, it will automatically or we have to initialize ourself the storage for capacity?