Can Anyone explain why String Buffer capacity and length is by default 16 | Sololearn: Learn to code for FREE!

+1

Can Anyone explain why String Buffer capacity and length is by default 16

2/25/2019 4:18:39 PM

Naresh Deeti

1 Answer

New Answer

+2

If you have a look in the documentation you will find different constructors for String Buffer. * StringBuffer() Constructs a string buffer with no characters in it and an initial capacity of 16 characters. * StringBuffer(CharSequence seq) Constructs a string buffer that contains the same characters as the specified CharSequence. * StringBuffer(int capacity) Constructs a string buffer with no characters in it and the specified initial capacity. * StringBuffer(String str) Constructs a string buffer initialized to the contents of the specified string. https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html I think only the designer of this class knows why he/she chooses 16. https://coderanch.com/t/455484/java/StringBuffer-size-charectors-java