• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between the StringBuilder and StringBuffer class

 
akshitha Akki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference seem to be StringBuilder being non-synchrinized and StringBuffer being synchronized. But I am not getting a clear idea on how it works.Can I please get a simple example to start getting the concept correct?
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods of StringBuffer class are synchronized although StringBuilder's not,hence faster performance.I don't care, how synchronization work for them.If you want to know, then read this Synchronized Methods .

-hth
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I suppose that's the difference.

This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.
Source: StringBuilder
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic