Solved

How to clear the contents of a StringBuffer in 1.1

Posted on 2000-04-04
11
321 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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
 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JList custom Cell Renderer refresh 15 57
eclipse shortcuts 9 55
HTTPSessionBindingListernter not configured in deployment descriptor 2 53
login form jsp example 2 25
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 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