• Post Reply Bookmark Topic Watch Topic
  • New Topic

String and StringBuffer  RSS feed

 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain me when to use String and when the StringBuffer in an application? and Which one is better?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer has a performance advantage when you concatenate a lot of variable parts into one string. You can try some experiments on your target platform to see when "a lot" becomes worth the effort of using a StringBuffer.

StringBuffer is also mutable, meaning you can change it, while String is not.

Look through the doc and compare methods. What can one do that the other cannot?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!