?
Solved

How to clear the contents of a StringBuffer in 1.1

Posted on 2000-04-04
11
Medium Priority
?
333 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

840 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