Solved

How to clear the contents of a StringBuffer in 1.1

Posted on 2000-04-04
11
320 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 80
create a gui in perl 3 72
Cipher Configuration on Apache HTTPD 4 53
oracle 11g 23 50
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

920 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

16 Experts available now in Live!

Get 1:1 Help Now