Register now or log in to join your professional community.
StringBuffer is synchronized, StringBuilder is not.
Literally Both serves the same purpose, But when it comes to the threads, you can go fpr SBuffer than SBuilder, Since SBuffer has internal mechanism to restrict its access to one thread at a time only.
Simply use StringBuilder unless you really are trying to share a buffer between threads. StringBuilder is the unsynchronized (less overhead = more efficient) younger brother of the original synchronized StringBuffer class.
StringBuffer is thread safe means it is synchronized but StringBuilder is not thread safe.
Functional wise both are similar as mutable. We should prefer StringBuffer if application is thread based else we can go with StringBuilder.