ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is difference between StringBuffer and StringBuilder in Java ?

user-image
تم إضافة السؤال من قبل Muhammed Rahshad Koyippalli , Cisco DNAC Senior Escalation Engineer , Cisco Systems - India
تاريخ النشر: 2014/05/24
Noushad Thottiyil Ali
من قبل 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
من قبل 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.

المزيد من الأسئلة المماثلة