On Thu, 19 Aug 1999, Ben Coppin wrote:

> You don't need to allocate space for a StringBuffer....
>
> you just create one:
>
> StringBuffer sBuffer = new StringBuffer ("");
>
> and then append to it as much as you like (until you run out of
> Virtual Memory I guess!)
[ ... ]

To turn this thread a bit, and connect it with some other recent
discussion about the performance benefits of using StringBuffer's (and
append) instead of String's (and concatenation), I've got a question
or two.  I can understand how performance is improved that way.  But
does that mean you should *always* use StringBuffers instead of
Strings and concatenation?  Because those are used all over the
place.

For example, suppose I do something as innocuous as:

out.println("The value of variableX is " + variableX + "<BR>");

Would it really be worth it to use a StringBuffer for what's being
output there?

Another alternative would be to use a combination of out.print's and
out.println's, a la:

out.print("The value of variableX is ");
out.print(variableX);
out.println("<BR>");

This gets rid of the concatenation, but at the penalty of additional
method calls.

I don't want to go crazy with this, I'm just trying to get a handle on
just how far to go with StringBuffer's.  Thanks.

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to