This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 10747

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: 44585
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!