Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

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.

9
  • 9
    Yes, StringBuilder doesn't need to re-create the String object over and over. Commented Sep 3, 2013 at 10:15
  • 186
    Dammit I used those 2 function to test a big string I'm working in. 6.51min vs 11secs Commented Oct 12, 2013 at 15:56
  • 1
    By the way you can use result += s; as well (in the first example) Commented May 28, 2015 at 13:39
  • 1
    how many object will be created by this statement? "{a:"+ a + ", b:" + b + ", c: " + c +"}"; Commented Mar 14, 2016 at 12:18
  • 2
    What about something like: String str = (a == null) ? null : a' + (b == null) ? null : b' + (c == null) ? c : c' + ...; ? Will that prevent the optimization from happening? Commented Jul 31, 2016 at 22:09