StringBuffer is obsolete?
It's obsolete in that new code on Java 1.5 should generally use StringBuilder
- it's very rare that you really need to build strings in a thread-safe manner, so why pay the synchronization cost?
I suspect code that you see using StringBuffer
mostly falls into buckets of:
- Written before Java 1.5
- Written to maintain compatibility with older JDKs
- Written by people who don't know about
StringBuilder
- Autogenerated by tools which don't know about
StringBuilder
Not everyone reads as widely as you :-)
I'm only half-joking. People copy code and patterns all the time. Many people don't stay in touch with API changes.
Why is StringBuffer obsolete? Because in the vast majority of cases, its synchronised behaviour isn't required. I can't think of a time I've ever needed it. Despite the fact that synchronisation is not now the performance issue it once was, it makes little sense to pay that tax in scenarios where it's unnecessary.