Well, it is acceptable,
but it more or less defeats the reasons of using a StringBuffer in the first
place.
"One"+"two"+"three" creates 3 String objects and to concatenate them, in the
background, another StringBuffer is created. So what you're doing is
equivalent to
sb.append(new StringBuffer("one").append("two").append("three").toString());

It's clear that the creation of this new StringBuffer is unnecessary
overhead.
A better suggestion is to use statements like
sb = sb.append("one").append("two").append("three");

Geert Van Damme

PS: Here we go again, 4 or 5 out-of-the-offices and 6 user unknowns.
Why is noone doing something about this????



> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Antonio W. Lagnada
> Sent: woensdag 29 november 2000 20:52
> To: [EMAIL PROTECTED]
> Subject: Re: StringBuffer
>
>
> Is this style acceptable fro a StringBuffer class?
>
> StringBuffer sb = new StringBuffer();
>
> sb.append("one" + "two" + "three");
> ..
> ..
> sb.append("four" + "five");
>
> --
> Antonio W. Lagnada
> Ecommerce Consultant
> [EMAIL PROTECTED]
>
> This email address is specifically
> for JSP-Interest email list.
> Remove _NOSPAM for the actual email.
>
>
>
> ---- "Sachin S. Khanna" <[EMAIL PROTECTED]> wrote:
> > Well the basic purpose of not using the String objects is because they
> > are
> > immutable, eat up a lot of memory and the whole exercise turns out
> > to be
> > inefficient. Therefore it is beter to use the StringBuffer Object.
> >
> > It would make no difference if you would create a number of StringBuffer
> > Objects to display your output as you would still be creating a lot
> > of
> > objects which would inturn use a lot of memory and this was exactly
> > the
> > reason why you were advised not to use the String Objects.
> > Best thing to do would be to create a single StringBuffer Object use
> > the
> > append method  for adding data ( as you are already doing ) and then
> > call
> > the toString() method on the StringBuffer Object to display the
> contents.
> > Have a nice day.
> > With regards,
> > Sachin S. Khanna.
> > www.emailanorder.com
> >
> > ----- Original Message -----
> > From: Sushil Singh <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Wednesday, November 22, 2000 5:21 AM
> > Subject: StringBuffer
> >
> >
> > > Hi,
> > >
> > > I have a question regarding String and StringBuffer class. Recently
> > I
> > > read that we should not use "+" concatenation since it will create
> > > temporary objects, instead we should use StringBuffer.  My JSP is
> > > producing series of System.out.println, like:
> > > .......
> > > some process
> > > ....
> > > System.out.println(new
> > > StringBuffer("test").append("test1").append("test2"));
> > > ----
> > > System.out.println(new
> > > StringBuffer("test3").append("test4").append("test5"));
> > > ----
> > > and so on.
> > >
> > > Now my question is that whether I should have one
> StringBuffer variable,
> > > append it and then displays or everytime "new StringBuffer".  Which
> > way
> > > is the best, any feedback will be highly appreciated.
> > >
> > > Thanks in advance.
> > >
> > > Sushil
> > >
> > >
> >
> ==================================================================
> =========
> > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > JSP-INTEREST".
> > > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> > DIGEST".
> > > Some relevant FAQs on JSP/Servlets can be found at:
> > >
> > >  http://java.sun.com/products/jsp/faq.html
> > >  http://www.esperanto.org.nz/jsp/jspfaq.html
> > >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> > >
> >
> >
> ==================================================================
> =========
> > To unsubscribe: mailto [EMAIL PROTECTED] with body:
> "signoff JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> > DIGEST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
>
> ___________________________________________________________________
> To get your own FREE ZDNet Onebox - FREE voicemail, email, and fax,
> all in one place - sign up today at http://www.zdnetonebox.com
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to