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

  • SEARCH
  • Home
  • 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 156469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:20:01+00:00 2026-05-11T10:20:01+00:00

I have often wondered this, is there a performance cost of splitting a string

  • 0

I have often wondered this, is there a performance cost of splitting a string over multiple lines to increase readability when initially assigning a value to a string. I know that strings are immutable and therefore a new string needs to be created every time. Also, the performance cost is actually irrelevant thanks to today’s really fast hardware (unless you are in some diabolical loop). So for example:

String newString = 'This is a really long long long long long' +     ' long long long long long long long long long long long long ' +     ' long long long long long long long long long string for example.'; 

How does the JVM or .Net’s compiler and other optimizations handle this. Will it create a single string? Or will it create 1 string then a new concatenating the value and then another one concatenating the values again?

This is for my own curiosity.

  • 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. 2026-05-11T10:20:01+00:00Added an answer on May 11, 2026 at 10:20 am

    This is guaranteed by the C# spec to be identical to creating the string in a single literal, because it’s a compile-time constant. From section 7.18 of the C# 3 spec:

    Whenever an expression fulfills the requirements listed above, the expression is evaluated at compile-time. This is true even if the expression is a sub-expression of a larger expression that contains non-constant constructs.

    (See the spec for the exact details of ‘the requirements listed above’ 🙂

    The Java Language Specification specifies it near the bottom of section 3.10.5:

    Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals.

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

Sidebar

Related Questions

I have often wondered why it is that non-English speaking programmers are forced to
I have often heard this term being used, but I have never really understood
I often have to convert a retreived value (usually as a string) - and
I've read plenty of articles about tuning GC in Java and have often wondered
Loose coupling is wonderful of course, but I have often wondered what overhead wiring
I have always wondered about this. So many application setups have a zip file
I have often wondered what exactly does casting do at compiler or machine level.
I have always wondered what the most effective way is of creating String's in
I have often seen this expression in a maintenance code Global[Name] What does this
I have often pondered this one... its probably an idiot question but here goes.

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.