Share:- Whatsapp Facebook Facebook

------------------------------------- Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.


0 votes
What is the difference between stringbuffer and stringbuilder in java?
in Java by

1 Answer

0 votes
StringBuider vs StringBuffer

Following are the difference between StringBuffer and StringBuilder in Java

1) StringBuffer is synchronized i.e. thread safe. It means two threads can't call the methods of StringBuffer simultaneously. StringBuilder is non-synchronized i.e. not thread safe. It means two threads can call the methods of StringBuilder simultaneously.

2) StringBuffer is thread-safe and StringBuilder is not. You can not share Instances of StringBuilder class between multiple threads. If such synchronization is required then it is better to use StringBuffer class.

3) StringBuilder is faster than StringBuffer because there is no overhead of acquiring and releasing locks associated with synchronized methods.

4) StringBuffer is old class and StringBuilder is relatively newer class. StringBuilder is introduced in release of JDK 1.5
by (4.3k points)