Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is difference between StringBuffer and StringBuilder in Java ?

user-image
Question added by Muhammed Rahshad Koyippalli , Cisco DNAC Senior Escalation Engineer , Cisco Systems - India
Date Posted: 2014/05/24
ahmad mohammed
by ahmad mohammed , JAVA team lead , edu-tek

StringBuffer is synchronized, StringBuilder is not.

Noushad Thottiyil Ali
by Noushad Thottiyil Ali , Associate Technical Delivery Manager , Accolite

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.

Mohammed Ameen
by Mohammed Ameen , Java Developer , TATA Consultancy Services Limited (TCSL)

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.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.