⟩ What is a StringBuffer class and how does it differ from String Class?
In contrast to the String class which implements immutable character strings, the StringBuffer class implements mutable character strings. Not only can the character string in a string buffer gets changed, but the buffer’s capacity can also change dynamically. The capacity of a String Buffer is the maximum number of characters that a string buffer can accommodate, before its size is automatically augmented.
Both String and StringBuffer class are thread-safe.
The syntax for initializing String class object is: String str1=”Hello”;
The syntax for initializing StringBuffer class object is:
StringBuffer sbr1= new StringBuffer (“hello”);
StringBuffer sbr2= new StringBuffer (10);
StringBuffer sbr3= new StringBuffer();