StringBuffer and StringBuilder

StringBuffer

A StringBuffer is represents strings in such a way that their data can be modified, that means it is mutable.
StringBuffer class object is mutable that means when we creates an object that can be change.

Creating StringBuffer object

We can create a StringBuffer object by using new operator and pass the string to the object, as:
StringBuffer sb=new StringBuffer(“Hello”);

StringBuilder

StringBuilder class is almost similar to to StringBuffer class. Their data can be modified, that means it is mutable.

Creating StringBuilder object

We can create a StringBuilder object by using new operator and pass the string to the object, as:
StringBuilder sb=new StringBuilder(“Hello”);

Leave a Reply

Your email address will not be published. Required fields are marked *