Difference between String and StringBuffer/StringBuilder in Java

The following table shows the differences between the String and StringBuffer/StringBuilder in Java Technology.


String
StringBuffer/StringBuilder
1
String Object is immutable.
StringBuffer/StringBuilder Object is mutable.
2
Immutable means the value stored in the String object can’t be changed.
Mutable means the value stored in the String object can be changed.
3
Inefficient
Efficient.
4
‘overloaded mathematical operators’ (‘+’) is used for adding strings which generates string new instances everytime.
Example:
String st = “Hello”;
st = st + “Java”;
‘append’ is used for adding two or more strings which expands  StringBuffer.
Example:
StringBuilder sb = new StringBuilder(“Hello”);
sb.append(“Java”);
5
String is not synchronized. Which means it is not thread safe.
StringBuilder/StringBuffer is synchronized. Which is thread safe and hence you can use it when you implement threads for methods.
6
Poor performance.
Better Performance.
7
Small amount of manipulation can be done.
Large amount or heavy amount of manipulation can be done.