There are many differences between String and (StringBuilder or StringBuffer) like mutability and many string operations
May be this question seems a bit silly, but I want to know for the sake of programming paradigm.
I want to ask, why has Java implemented another class, StringBuilder or StringBuffer for a data structure like String. Why have they not given those features in String itself.
Why not make String itself thread-safe or provide some extra features that StringBuilder or StringBuffer has?
Stringis immutable,StringBuilderis mutable. It's as simple as that. You can't add theStringBuilderfeatures toString, because they're all about mutability.