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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:31:02+00:00 2026-06-17T20:31:02+00:00

I would like to know about the relation between string literal and java performance.

  • 0

I would like to know about the relation between string literal and java performance.

for example, uses of below statements number of times makes any impact in performance.I have thousands of classes and many time we are using below statements :

1) buffer.append(",");
2) buffer.append("}");

3)String.append("10,000 times...same lines") // printing same lines in many classes
3)String.someStringMethod("same line many times") // using any String method 

Does this cause performance impact in terms of memory management etc.Do we have any cleaner way ?

Thanks

  • 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-06-17T20:31:03+00:00Added an answer on June 17, 2026 at 8:31 pm

    It is really difficult to comment on examples that make no sense. However:

    • In general there are no particular efficiency concerns with Java String literals.
    • In general there are no particular efficiency concerns with methods that take String literals as arguments.
    • String concatenation / building can present efficiency concerns if a particular piece of code is executed often enough. However, if you need to build strings, then there is not a lot you can do about it.

    There are one or two things that it is worth taking steps to avoid. The main one is this:

       String s = "";
       for (/* lots of times */) {
           // do stuff
           s += someOtherString;
       }
    

    The problem is that this generates and then discards lots of temporary Strings. The more efficient way to do it is this:

       StringBuilder sb = new StringBuilder();
       for (/* lots of times */) {
           // do stuff
           sb.append(someOtherString);
       }
       String s = sb.toString();
    

    However, it is probably only worth while optimizing this kind of thing if the profiler tells you that this particular bit of code is a bottleneck.

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

Sidebar

Related Questions

my query is about architecture and relation of classes, I would like to know
I would like to know about how NULL values affect query performance in SQL
I would like to know about the various options for distributing a Java application.
I would like to know about what is the relationship between JNDI and Spring?
I would like to know about the below approach to perform CRUD operations on
I would like to know about the Invoke(delegate) method. I do not understand why
I am just learning and would like to know about a piece of code
I would like to know more about how the thread sleep resolution works, and
I would like to know your opinion about using Cassandra to implement a RBAC-like
I know about git diff branch1 branch2 . However, I would like to see

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.