Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Vs StringBuffer

 
Reggie McDougal
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If creating a string with lots of data should I use a stringBuffre instead of the following...



Is there a better way of doing this if sh can some one give me some example code.

Reg
 
Mike Gershman
Ranch Hand
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your one line concatenations work fine as a String.

StringBuffer has the edge where you are building up a String out of many pieces, perhaps in a loop.
 
Sanjaya Sugiarto
Ranch Hand
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And StringBuffer has a big performance benefit too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic