One possible work around could be :
int end = temp.length();
temp = temp.delete(0,end);
Have a nice day.
With regards,
Sachin S. Khanna.
www.emailanorder.com
----- Original Message -----
From: Sushil Singh <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 23, 2000 1:35 AM
Subject: Re: StringBuffer
> Thanks, but once the StringBuffer is having some data and I printed using
> System.out, for the next time I have to recreate the StringBuffer by
eliminating
> the previous content, what method I should use.
> StringBuffer temp = new StringBuffer();
> temp.append("test1");
> temp.append("test2");
> System.out.println(temp);
> temp = new StringBuffer();
> temp.append("test111");
> temp.append("test222");
> System.out.println(temp);
> This is the correct way, if I make StringBuffer null, its giving
> NullPointerException.
>
> Is there any way, to directly overwrite the StringBuffer content with new
content.
>
> Thanks in advance.
>
> Sushil
>
> "Sachin S. Khanna" 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 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