Thursday, 27 July 2017

Differences between StringBuffer and StringBuilder

StringBuilder is exactly same as that of StringBuffer( including methods and constructors) except the following differences.

Sl No
Every methods present in StringBuffer is synchronized.
No method present in StringBuilder is synchronized.
At a time only one thread is allowed to operate on StringBuffer object. Hence, StringBuffer object is thread safe.
At a time multiple threads are allowed to operate on StringBuilder object and hence StringBuilder object is not thread safe.
It increases waiting time of threads and relatively performance is low.
Threads are not required to wait to operate on StringBuilder object and hence relatively performance is high.
Introduced in 1.0 version
Introduced in 1.5 version.

If you like the post, please comment, share the post and do like me on Facebook.

Thanks & Regards,
Susanto Paul