StringBuffer is very much like Strings but it has an edge we it comes to altering Strings. StringBuffer can be modified which is not the case when using Strings. If you are using String and try to alter it, it is internally converted into StringBuffer, altered and then a new String is created with the altered value. This all is done internally and takes some resources.

Syntax of declaring StringBuffer is as follows:

Java Code:
StringBuffer sb = new StringBuffer("MyString");
Java Code: