StringBuilder v/s StringBuffer

Hi All,

I want to know the difference between StringBuilder & StringBuffer classes. I know that StringBuffer is thread safe and StringBuilder is not, but any practical examples and code would be appreciated. Also, if we mark the methods written for StringBuilder objects as 'synchronized', would they become thread safe? please respond soon, its urgent.

But back to my main question, please share sample code to show the difference in behavior of these two classes, when multiple threads are involved.

No you can't involve with multiple thread in StringBuilder.

In most of the cases I prefer StringBuffer. Because in real world application we have to deal with large number of threads. I check this in th past using JUnit test. I don't have a sample code for this now. If you can just write a simple application and do a unit test. You can see it your self.

Again all those things comes to the picture in real world, because of multi threading. In single thread application, which is the most common situation we comes up with, if you can avoid the overhead of synchronization the StringBuilder makes little faster actually.