How to clear the contents of a StringBuffer in 1.1

Hi,
I'm trying to clear out the contents of a string buffer in Java 1.1, can anybody supply the necessary code.
I know 1.2 provides replace and delete methods but they are not available to me in 1.1

Any ideas out there ?
rfahertyAsked:
Who is Participating?
 
azawawiConnect With a Mentor Commented:
so r u going to give me my points or not ? i deserve it :)
0
 
azawawiCommented:
use StringBuffer.setLength(int len), and set len to zero....

StringBuffer sb = new StringBuffer();
sb.append("Hello");            
sb.setLength(0);
// sb is now empty...

Hope that this helps...
0
 
azawawiCommented:
use StringBuffer.setLength(int len), and set len to zero....

StringBuffer sb = new StringBuffer();
sb.append("Hello");
sb.setLength(0);
// sb is now empty...

Hope that this helps...

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
rfahertyAuthor Commented:
Hi Azawawi,
thank you for you reply. I tried it but it did not work. Howeever I tried the followiung which did work :

StringBuffer sb = new StringBuffer();
sb.append("Hello");
sb = new StringBuffer();
// sb.setLength(0);
// sb is now empty...


0
 
azawawiCommented:
strange i tried it @ MS jview (1.1) and it worked... plus i tried it in JDK and it worked...
0
 
rfahertyAuthor Commented:
Hi Azawazi,
I'm using Visual J++ 1.1 and it doesn't work in that !
Very frustrating.
0
 
azawawiCommented:
What JDK are u using?
because i think StringBuffer.setLength(int len) is there from JDK 1.1

0
 
azawawiCommented:
hmmm...
but it worked in Visual J++ 6.0, JDK 1.1 and everything...

Visual J++ 1.1 is old news...
0
 
rfahertyAuthor Commented:
Hello again,
The setlenght(0) should work but for whatever reason it isn't in my development environment. I guess the lesson I've learnt is to upgrade my envoronment !
0
 
rfahertyAuthor Commented:
Fair enough, for sticking with the problem you canb have them,
Thanks !
0
 
anand29Commented:
Recreate the instance of StringBUffer
i.e.

StringBuffer buf=new StringBuffer();
buf.append("TEST");
buf=new StringBuffer();
it will be cleared try this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.