13.Q.Difference between StringBuffer and StringBuilder

Category: JAVA STRING INTERVIEW QUESTIONS AND ANSWERS

Answer :

The basic difference between StringBuffer and StringBuilder is Thread safety and Synchronization .

StringBuffer is Synchronized and thread-safe due to which multiple threads can safely use it . While StringBuilder is not Synchronized and so not thread-safe .

StringBuffer is slower due to synchronization overhead. Whereas StringBuilder is fast as it avoids locking mechanisms .

Leave a Reply

Your email address will not be published. Required fields are marked *