• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

StringBuffer or String

 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
When would I use a StringBuffer? it seems to cause alot of overhead, StringBuffer.append() over and over again when you use +.
Can someone tell me the 'practical' diffrence. I've read the API but it didn't really explain to me which one is considered better.
Thanks.
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say <CODE>StringBuffer</CODE> is better when doing a lot of appending. No new object has to be created whereas with <CODE>String</CODE>, every += releases one object and creates a new one.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is interesting to see String objects as a thread safe ones. I haven't really seen the problems with a StringBuffer being modified by multiple threads. Has anybody come across?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!