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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:11:00+00:00 2026-05-22T22:11:00+00:00

I am not an expert in Java; I am hoping that someone on this

  • 0

I am not an expert in Java; I am hoping that someone on this list who are more proficient in Java can help me out.

I have the following codes on my current server.

<cfset var buffer = CreateObject("java", "java.lang.StringBuffer").init("") />
<cfset buffer.append(variables.myVar) />

I am trying to move these codes to another server. The problem is that this new server (shared hosting) does not allow invoking of a Java Object. So, I changed them to the followings.

<cfset var buffer = "" />
<cfset var buffer = buffer & variables.myVar />

My question is, are the new codes equivalent to the old ones? What are the advantages of using java.lang.StringBuffer?

Thanks in advance,
Monte

  • 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-22T22:11:00+00:00Added an answer on May 22, 2026 at 10:11 pm

    No, the “new” code is less efficient when used in a heavy loop.

    You can emulate StringBuffer with an array.

    <cfset var buffer = ArrayNew(1)>
    <cfset ArrayAppend(buffer, variables.myVar1)>
    <cfset ArrayAppend(buffer, variables.myVar2)>
    <!--- more of these --->
    <cfset result = ArrayToList(buffer, "")>
    

    However: If you are not concatenating hundreds or thousands of strings in a row, there is little benefit in using StringBuffer. You can go with & in most cases.


    I have done some testing (on a ColdFusion 7 server w/ Java 1.4, more recent editions might score differently).

    All times are milli-seconds The results are averaged over 10 repeats (except the one in square brackets as this took virtually forever).

    The following is the measurement of iteratively concatenating a single letter N times.

    iterations   concat   array   cfsave   string
                                 content   buffer
           100        0       0        0        2
          1000        4       4        2       22
         10000      168      29       33      219
        100000   30,781     168      293    1,575
    

    The following is the result of iteratively concatenating a string of length 10 N times:

    iterations   concat   array   cfsave   string
                                 content   buffer
           100        0       0        0        4
          1000       25       0        2       24
         10000    1,242      33       31      232
        100000 [410,979]    180      373    2,082
    

    Note how basic string concatenation gets rapidly more inefficient the more iterations you do and the longer the string gets. The other methods show more linar behavior.

    Further notice that the StringBuffer’s performance is also tied to its initial size. If you dimension it too small (i.e. by calling init("") instead of .init(10000), for example) then it is forced to re-allocate more space when it runs out, which also takes time. For the sake of test, I initialized it with exactly the amount of space it would need.

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

Sidebar

Related Questions

Ok so I'm not Java expert but I'm just programming this java applet game
This is related to this question . I'm not an expert on Linux device
$(document).ready(function() { $(span.link).mouseover(function(e){ $(this.children).css(display,inline); }); }); I'm not a javascript expert, but I've cobbled
I'm not considering this - I'm comfortable with C# and VB, but an expert
I have exceptions created for every condition that my application does not expect. UserNameNotValidException
(Not related to versioning the database schema) Applications that interfaces with databases often have
First off I'm not a Java expert by any stretch, nor am I a
I have a Java application that is generating JasperReports. It will create as many
This is for the swing experts out there. I have spent considerable time on
I not a DB expert, so am looking for advice for a web-based system

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.