Solved

How to clear the contents of a StringBuffer in 1.1

Posted on 2000-04-04
11
319 Views
Last Modified: 2008-03-10
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 ?
0
Comment
Question by:rfaherty
  • 6
  • 4
11 Comments
 
LVL 2

Expert Comment

by:azawawi
ID: 2683214
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
 
LVL 2

Expert Comment

by:azawawi
ID: 2683215
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
 

Author Comment

by:rfaherty
ID: 2683234
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
 
LVL 2

Expert Comment

by:azawawi
ID: 2683241
strange i tried it @ MS jview (1.1) and it worked... plus i tried it in JDK and it worked...
0
 

Author Comment

by:rfaherty
ID: 2683250
Hi Azawazi,
I'm using Visual J++ 1.1 and it doesn't work in that !
Very frustrating.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Expert Comment

by:azawawi
ID: 2683253
What JDK are u using?
because i think StringBuffer.setLength(int len) is there from JDK 1.1

0
 
LVL 2

Expert Comment

by:azawawi
ID: 2683261
hmmm...
but it worked in Visual J++ 6.0, JDK 1.1 and everything...

Visual J++ 1.1 is old news...
0
 

Author Comment

by:rfaherty
ID: 2683266
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
 
LVL 2

Accepted Solution

by:
azawawi earned 250 total points
ID: 2683276
so r u going to give me my points or not ? i deserve it :)
0
 

Author Comment

by:rfaherty
ID: 2683281
Fair enough, for sticking with the problem you canb have them,
Thanks !
0
 
LVL 2

Expert Comment

by:anand29
ID: 2684823
Recreate the instance of StringBUffer
i.e.

StringBuffer buf=new StringBuffer();
buf.append("TEST");
buf=new StringBuffer();
it will be cleared try this.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now