StringBuilder

Advertisements

Prev Tutorial Next Tutorial

StringBuilder

It is a predefined class in java.lang package can be used to handle the String. StringBuilder class is almost similar to to StringBuffer class. It is also a mutable object.
The main difference StringBuffer and StringBuilder class is StringBuffer is thread safe that means only one threads allowed at a time to work on the String where as StringBuilder is not thread safe that means multiple threads can work on same String value.

Difference between StringBuffer and StringBuilder

All the things between StringBuffer and StringBuilder are same only difference is StringBuffer is synchronized and StringBuilder is not synchronized. synchronized means one thread is allow at a time so it thread safe. Not synchronized means multiple threads are allow at a time so it not thread safe.

StringBufferStringBuilder
1It is thread safe.It is not thread safe.
2Its methods are synchronized and provide thread safety.Its methods are not synchronized and unable to provide thread safety.
3Relatively performance is low because thread need to wait until previous process is complete.Relatively performance is high because no need to wait any thread it allows multiple thread at a time.
1Introduced in 1.0 version.Introduced in 1.5 version.

When we use String, StringBuffer and StringBuilder

  • If the content is fixed and would not change frequently then we use String.
  • If content is not fixed and keep on changing but thread safety is required then we use StringBuffer
  • If content is not fixed and keep on changing and thread safety is not required then we use StringBuilder

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements