16 June 2022
16 June 2022
String Buffer:
• If a user wants to change the content frequently then it is
recommended to go for StringBuffer.
• StringBuffer objects are mutable, so they can be modified. • We
can create a StringBuffer object by using new operator and pass the
string to the object, as:
StringBuffer sb = new StringBuffer (“Sujatha");
• The default initial capacity of a StringBuffer is"16". • After
reaching its maximum limit it will be increased to
(currentcapacity+1)*2. ie; (16+1)*2.
StringBuffer Methods
Method Description
Method Description
StringBuilder
⚫ String Builder will be having same methods as
of StringBuffer except the following differences.
StringBuffer StringBuilder
➢ Use String if you require immutability use Stringbuffer in java if you need
without thread-safety.