Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 5
    Why do I prefer StringBuilder to the plus notation? Commented May 18, 2009 at 16:44
  • 10
    Efficiency, or rather an often-misguided attempt at it. Commented May 18, 2009 at 16:55
  • 2
    The attempt at efficiency is based, I think, on the fact that the Java compiler implements the string concatenation operator using StringBuilder (StringBuffer in pre-1.5 compilers). There is an old, but well-known article stating that there are performance benefits in certain situations to using StringBuffer (or StringBuilder, now). Here's the link: java.sun.com/developer/JDCTechTips/2002/tt0305.html Commented May 18, 2009 at 17:32
  • 6
    Only when the compiler can't do it. For literals and constants, if you use a plus sign, the concatenation is done at compile-time. Using a StringBuilder forces it to happen at runtime, so it's not only more work, it's slower. Commented May 9, 2011 at 7:30