|
| |||||||||
| Tags: buffer, datatypes, empty, int, java, string, string buffer |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Empty StringBuffer in java
Hello, Is there a clean and efficient way to clear an instance of StringBuffer. I have a loop in which I use a StringBuffer to avoid creating too many instances of String, but each iteration of the loop I would have my new empty StringBuffer. Any help on this will be appreciated. Thanks for your help. |
|
#2
| |||
| |||
| Re: Empty StringBuffer in java
Hello, I do not know what exactly you are using the string buffer for, I have a code with me, see if this helps you. Here is the code Code: StringBuffer d = new StringBuffer ( "ghjghj"); d.append ( "dsdfsdf"). append ( "sdfsdf"); / / Empty StringBuffer d.delete (0, d.length ()); |
|
#3
| |||
| |||
| Re: Empty StringBuffer in java
Hello, Another way is to use the method setLength like this, I do not know that this is what you need. Here is the method you can use it in your code Code: mnstring.setLength(0); |
|
#4
| |||
| |||
| Re: Empty StringBuffer in java
Hello, I think I misunderstood the delete method, according to the JavaDoc, I thought it returned an stringBuffer, but really did not erase the original stringBuffer. The alternative seems to me very well or I think this is easy to implement in my code, i would rather go with the same. By the way thanks for your replies they helped me a lot and also if you have some more interesting information on the this then please do post back. |
|
#5
| |||
| |||
| Re: Empty StringBuffer in java
Hello, Most methods StringBuffer return a StringBuffer which in fact corresponds to the current object. In code this is summarized by the following code: Code: return this; Code: sb.append("Hello").append(" ").append("World"); |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Empty StringBuffer in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can't empty recycle bin | Norman Stein | Windows XP Support | 11 | 19-12-2011 01:40 AM |
| JAVA/Stutter.J.2 is a virus or any kind of java file | GaganjyotTechie | Networking & Security | 6 | 29-05-2011 10:55 AM |
| Differentiation among StringBuffer and StringBuilder class | Ram Bharose | Software Development | 5 | 27-01-2010 02:20 PM |
| Difference between String and StringBuffer. | Luz | Software Development | 3 | 01-12-2009 10:13 PM |
| Link List Example in Java Sample program in Java | trickson | Software Development | 2 | 04-08-2009 09:23 PM |