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

What is the difference between stringbuffer and stringbuilder in java

0 votes
12 views
What is the difference between stringbuffer and stringbuilder in java?
asked Aug 30, 2017 in Java by Nikhil Kumar

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
answered Aug 30, 2017 by ranju_12 (2,060 points)
...