Search code examples
javastringbuilderstringbuffer

Stringbuffer,Stringbuilder when to use?


Possible Duplicate:
StringBuilder and StringBuffer in Java

Criteria to choose among StringBuffer and StringBuilder


Solution

  • If you're definitely using Java 5 or higher, and you definitely don't need to share the object between threads (I can't remember ever needing to do so), StringBuilder is a better bet.

    Basically you should almost always use StringBuilder when you can, to avoid pointless synchronization. Admittedly the way most VMs handle uncontended synchronization is extremely efficient, but if you don't need it in the first place...