File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to trim a StringBuffer??!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to trim a StringBuffer??!!" Watch "how to trim a StringBuffer??!!" New topic

how to trim a StringBuffer??!!

Bharat Macwana

Joined: May 31, 2007
Posts: 3
Hi Ranchers!!

is this the best way to trim a StringBuffer?

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10826

In your code, you are trimming the string and not the buffer.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
You mean s.trim(), surely?

You should usually use StringBuilder instead, and there appears to be a suitable method if you look through its documentation.
I agree. Here's the link:
subject: how to trim a StringBuffer??!!
It's not a secret anymore!