Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What is difference between StringBuffer and StringBuilder in Java ?

user-image
Question ajoutée par Muhammed Rahshad Koyippalli , Cisco DNAC Senior Escalation Engineer , Cisco Systems - India
Date de publication: 2014/05/24
ahmad mohammed
par ahmad mohammed , JAVA team lead , edu-tek

StringBuffer is synchronized, StringBuilder is not.

Noushad Thottiyil Ali
par 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
par 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

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?