In the book \"Effective Java\", Josh Bloch says that
StringBuffer is largely obsolete and should be replaced by the non-synchronized implementation \'S
Why is the StringBuffer class now obsolete?
Because its operations are synchronized, which adds overhead and is rarely useful.
The reason why you still see StringBuffer
used widely is simply inertia: There are still countless code examples tutorials out there that were never updated to use StringBuilder
, and people still learn outdated practices (not just this one) from such sources. And even people who know better often fall back to old habits.