Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to trim a StringBuffer??!!

 
Bharat Macwana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers!!

is this the best way to trim a StringBuffer?

 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code, you are trimming the string and not the buffer.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic