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 427473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:34:51+00:00 2026-05-12T19:34:51+00:00

Strings are immutable, meaning, once they have been created they cannot be changed. So,

  • 0

Strings are immutable, meaning, once they have been created they cannot be changed.

So, does this mean that it would take more memory if you append things with += than if you created a StringBuffer and appended text to that?

If you use +=, you would create a new ‘object’ each time that has to be saved in the memory, wouldn’t you?

  • 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-12T19:34:52+00:00Added an answer on May 12, 2026 at 7:34 pm

    Yes, you will create a new object each time with +=. That doesn’t mean it’s always the wrong thing to do, however. It depends whether you want that value as a string, or whether you’re just going to use it to build the string up further.

    If you actually want the result of x + y as a string, then you might as well just use string concatenation. However, if you’re really going to (say) loop round and append another string, and another, etc – only needing the result as a string at the very end, then StringBuffer/StringBuilder are the way to go. Indeed, looping is really where StringBuilder pays off over string concatenation – the performance difference for 5 or even 10 direct concatenations is going to be quite small, but for thousands it becomes a lot worse – basically because you get O(N2) complexity with concatenation vs O(N) complexity with StringBuilder.

    In Java 5 and above, you should basically use StringBuilder – it’s unsynchronized, but that’s almost always okay; it’s very rare to want to share one between threads.

    I have an article on all of this which you might find useful.

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

Sidebar

Related Questions

Given that strings are immutable in .NET, I'm wondering why they have been designed
Strings are immutable, does it mean that i always have to do something like
I read today, in c# strings are immutable, like once created they cant be
One would expect that even though strings are immutable, value-equality and reference-equality would not
Is this possible? Given that C# uses immutable strings, one could expect that there
Strings are reference types, but they are immutable. This allows for them to be
I have heard and read that a string can not be changed (immutable?). That
In .NET, strings are immutable and are reference type variables. This often comes as
As almost everybody knows strings in Java are immutable. Recently I discovered something that
I have read in a Java book that says: Because a String is immutable,

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.