The differences between the String and StringBuffer is given in the table below.
String :
1) The String class is immutable.
2) The String is slow and consumes more memory when you concat too many strings because every time it creates a new instance.
3) The String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method.
String Buffer:
- The StringBuffer class is mutable.
- The StringBuffer is fast and consumes less memory when you cancat strings.
- The StringBuffer class doesn't override the equals() method of Object class.