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
StringBuffer
StringBuilder
1.
Every methods present in StringBuffer is synchronized.
No method present in StringBuilder is synchronized.
2
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.
3
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.
4
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