• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Cleanup StringBuffer

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How can I cleanup the buffer(if somebody can explain me with syntax)?
Thanks in advance,
Angela
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe stringBuffer.setLength(0); should do your job.
D.J
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Dean J",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dean,
Is stringbuffer.setLength(0) method clears the buffer ?
Plz let me know,
Thanks in advance,
Angela
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
The setLength method of stringbuffer when used with an int constructor will set the length of the buffer to whatever the integer argument is. Using zero will essentially set the length to zero, effectively clearing the buffer. For more info on String buffer see...
http://java.sun.com/products//jdk/1.2/docs/api/java/lang/StringBuffer.html
Pat B.
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pat,
Also String buffer append method will start appending at starting point in the memory while other application running in the memory?
Thanks,
Angela

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Angela Jessi:
Thanks Pat,
Also String buffer append method will start appending at starting point in the memory while other application running in the memory?
Thanks,
Angela


Angela can you explain your question ?
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Siva,
We have Global Heap memory where java application runs. while java application is running, it allocates some memory in global heap. Now if I have allocated memory for String Buffer, and when I used append method to insert some data, it will start appending at starting point in Global Heap Memory or it will append the data to applications which is running.
Plz let me know for further clarification,
Thanks again Siva,
Angela
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The delete(start,end) method would also work:
buffer.delete(0,buffer.length()-1);
Enjoy!

------------------
Chris Stehno (Sun Certified Programmer for the Java 2 Platform)
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In answer to the "Heap" posting ... one of the nice things about Java is that you don't have to care (for the most part) about your memory management. The internals do all that for you. The code that I just posted is all that you have to do ... any memory reallocation is done by the JVM.
------------------
Chris Stehno (Sun Certified Programmer for the Java 2 Platform)
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris for your reply....
Angela
 
It runs on an internal combustion engine. This ad does not:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic