This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why use StringBuffer?

 
Roy Tock
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's String class is pretty easy to use. I think it's a well-designed class.
I understand that String concatenation using + actually uses StringBuffer under the hood (so saith the J2SE 1.3 API spec). Other than that, what practical use is there for StringBuffer in real programs?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that some code like this will be altered by the compiler:

and this is fine, since it's more efficient but happens under the covers so you don't have to worry about it.
If you're building a String in a loop, it can't be done so you have to use a StringBuffer

Coolies?
Dave
 
Roy Tock
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic