JAVA Stringbuffer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

JAVA Stringbuffer

Example : Stringbuffer example = new Stringbuffer(5); the 5 was the capacity/size for the Stringbuffer as i know, but can anyone show me what the 5 mean,i mean how many int i can add to it to reach it maximum size

4th Aug 2019, 10:54 AM
Tzion
Tzion - avatar
1 Answer
+ 1
capacity grows dynamically so you can append an almost arbitrarily long string, (it is limited with the max value of the used index (int) and capacity of your memory only.) without parameters, initial capacity is 16, if you know your minimal capacity is eg about 512 you can help set better initial capacity. StringBuilder is the newer faster version of it
4th Aug 2019, 2:15 PM
zemiak