Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6701921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:59:30+00:00 2026-05-26T06:59:30+00:00

Possible Duplicate: Stringbuilder vs String.Concat As I understand it, String are immutable, so if

  • 0

Possible Duplicate:
Stringbuilder vs String.Concat

As I understand it, String are immutable, so if you do "one " + "two", rather than reusing the memory of these two strings, a new string is created with value “one two”. This becomes a problem if you do something like:

String output = "";
for (int i = 0; i < 20; i++){
    output = output + ii.toString();
}

Because 19 (or 39?) strings are created and discarded to produce the final desired output.

String builders are mutable, so you can add strings together efficiently, and then convert them into a string when you are done.

I assume there is some overhead in creating string builders, and also the clever compilers used today optimize away lots of string addition problems. So my question is: how many strings do I need to add together before it becomes more efficient to use a StringBuilder instead? Or are my assumptions incorrect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:59:31+00:00Added an answer on May 26, 2026 at 6:59 am

    An answer in this question – Does StringBuilder use more memory than String concatenation? – states ‘a few dozen’ is the threshold.

    And linked from another answer in that question is this link – http://www.codinghorror.com/blog/2009/01/the-sad-tragedy-of-micro-optimization-theater.html – which concludes with “it doesn’t matter”!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: Is String.Format as efficient as StringBuilder C# String output: format or concat?
Possible Duplicate: String vs StringBuilder I just revisited some of the books that I
Possible Duplicate: String concatenation vs String Builder. Performance Any difference (performance and memory usage)
Possible Duplicate: String vs StringBuilder Hi, I'm creating a json string. I have some
Possible Duplicate: Difference between string and StringBuilder in c# What’s the difference between System.String
Possible Duplicate: LINQ to append to a StringBuilder from a String[] Forgive my functional
Possible Duplicate: String, StringBuffer, and StringBuilder what is the difference (advantages, disadvantages) between using
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: Converting string in C# I want to camelize a string, for example:
Possible Duplicate: most elegant way to return a string from List<int> I'm not sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.