Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding StringBuffers and StringBuilders

 
praveen raaj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
can you explain to me what is the common use for StringBuffers and StringBuilders?
 
Patel Chintan
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer and StringBuilder classes are both used to create mutable string objects which is not possible with String class the only difference between the two is already stated by chintan.
 
Afzal Rehman
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer is syncronized
StringBuilder is unsyncronized.
StringBuffer and StringBuilder are mutable.
StringBuilder was added in java 5 API it's same as StringBuffer except is not thread safe
StringBuilder is faster then StringBuffer as performance point of view.
 
Phungsuk Wangdu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well common use could be if we want mutable string objects
and both are used as an alternative to stiring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic