The StringBuffer class is used to create mutable string. It is same as String class except it is mutable and thread-safe. Let's see the examples of append(), insert(), replace(), delete(), replace() and ensureCapacity() methods.
The StringBuilder class is used to create mutable string. It is same as String class except it is mutable. Let's see the examples of append(), insert(), replace(), delete(), replace() and ensureCapacity() methods.
Difference between StringBuffer and StringBuilder in java, let's see the StringBuffer vs StringBuilder in java with examples, there is given a list of main differences between StringBuffer and StringBuilder.
There are many immutable classes like String, Boolean, Byte, Short, Integer, Long, Float, Double etc. In short, all the wrapper classes and String class is immutable. We can also create immutable class by creating final class that have final data members as the example given below:
If you want to represent any object as a string, toString() method comes into existence. The toString() method returns the string representation of the object. If you print any object, java compiler internally invokes the toString() method on the object. So overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation.