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

1 Answer

0 votes
by (5k points)
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

Share:- Whatsapp Facebook Facebook


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

Categories

...