While what Ben said is true, there may be some mileage in using the
StringBuffer's ensureCapacity method or using the constructor with an int
parameter.
It depends on how good an estimate you can make of the final length and how many
appends you are likely to make: whenever you append something that would take it
beyond current capacity a new allocation is made. Bear in mind the default
initial capacity is 16 characters.
- simon
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!)
>
> sBuffer.append ("some extra text");
>
> the Java Virtual Machine will handle allocating and deallocating it for you.
>
> Ben
>
> -----Original Message-----
> From: Kathiresan, Vallikun [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 19, 1999 1:42 PM
> To: [EMAIL PROTECTED]
> Subject: Preallocate space
>
> Any suggestions about preallocating space with a StringBuffer? Is it
> recommended or ..? Any suggestions appreciated.
>
> Thanks
> Vallikun
___________________________________________________________________________
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