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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:14:39+00:00 2026-05-24T19:14:39+00:00

All, Why is it suggested that the size of the StringBuffer / StringBuilder object

  • 0

All,

Why is it suggested that the size of the StringBuffer/StringBuilder object should be initialized to a size of 2^{1…n}(Though usually it would be > 64). What would be the advantage/optimization would be achieved doing so?

  • 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-24T19:14:40+00:00Added an answer on May 24, 2026 at 7:14 pm

    What would be the advantage/optimization would be achieved doing so?

    I don’t think there is any advantage at all in doing this.

    My advice would be to pick an initial size that is just a bit larger than the expected size … if you have a moderately good estimate. If you don’t have an estimate, you won’t gain much by supplying an initial size at all.

    Using an initial size that is a significant over-estimate is not a good idea. It wastes space, and the JVM will have to zero all of those characters that you don’t use at some point which costs CPU / memory cycles.

    [It should be possible empirically figure out the cost of under- and over-estimating the sizes, and compare with the costs of using the default initial size. However, the numbers are likely to depend on how good the JIT optimizer is, and things like how fast memory can be copied versus how fast it can be zeroed. In other words, they will be platform specific.]

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

Sidebar

Related Questions

As suggested I allow all of my WPF UIElement s to have a dynamic
All the examples I've seen of sock.listen(5) in the python documentation suggest I should
Profiling my cpu-bound code has suggested I that spend a long time checking to
I've seen this problem on the web, and all the suggested solutions aren't working
Assume that the data X has size 1000 *1000. X is displayed using the
I'm trying to query my SQLite DB for all rows that have a particular
How is it possible in QML to automatically stretch element so that all its
I've heard that using 'em' for font size is recommended. I've tried it, but
I wonder if anyone could suggest the best way of looping through all the
All the articles I've found via google are either obsolete or contradict one another.

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.