String is an immutable object, once constructed they cannot be changed anymore.That means, whenever you “change” the value of a String, you create a new object basically and make that variable reference this new object. Appending a String to another existing one is the same kind of deal and here old object is always dropped.
So for manipulating string means there is more to copy and more garbage is produced that is less performing.
So when we need to manipulate string, it is better to use SrtringBuffer or StringBuilder.
StringBuilder and StringBuilder are mutable object. So when I/O gets large, we should use StringBuilder and StringBuilder.
Both of them are basically same. The difference between them is, StringBuilder is not thread safe, in others words, its methods are not synchronized. So it is recommended to use StringBuilder instead of StringBuffer whenever possible, because StringBuilder will run faster.