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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:39:44+00:00 2026-05-27T10:39:44+00:00

Which one will be better use for Concatenation of String If i want to

  • 0

Which one will be better use for Concatenation of String

If i want to build a string from bunch of string variables such as str1 and str2,
which one will be better one ???

  1. String Concat operator

String str="This the String1 " + str1 + " merged with Sting2 " + str2;

  1. String format method

String str=String.format("This the String1 %s merged with Sting2 %s", str1 , str2);

What i think is second one will be better , because first one will suffer from creation of lot of string.

correct me if i am wrong ? and provide feedback on same

  • 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-27T10:39:45+00:00Added an answer on May 27, 2026 at 10:39 am

    The first won’t actually create any extra strings. It will be compiled into something like:

    String str = new StringBuilder("This the String1 ")
        .append(str1)
        .append(" merged with Sting2 ")
        .append(str2)
        .toString();
    

    Given that the second form requires parsing of the format string, I wouldn’t be surprised if the first one actually runs quicker.

    However, unless you’ve got benchmarks to prove that this is really a bit of code which is running too slowly for you, you shouldn’t be too worried about the efficiency. You should be more worried about readability. Which code do you find more readable?

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

Sidebar

Related Questions

which one will be better to use default magic quotes or user defined addslash/stripslash
Hi I want to send message from one application (which will be installed on
I want to create one new model class, which will be extended in all
My question is which one is better to use? As NSTimer in turn uses
sIFR 2 or sIFR 3 Beta which one is better to use and why
i want to use a list which will store objects of some type (lets
I'm trying to write a single query which will include one of the two
We are setting up two server systems. One of which will host a 3rd
I'm creating a class that will have one public method, which returns a value
I will have a screen in which there will be 11 images one below

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.