Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to clear the contents of a StringBuffer in 1.1

Posted on 2000-04-04
11
323 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
How to convert String matching to regex in java 4 49
servlet example 17 51
Notify sent to other threads in Java 9 33
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

856 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