Sunday, 18 September 2016

StringBuffer and StringBuilder

13.7 Difference b/w StringBuffer and StringBuilder

Difference between StringBuffer and StringBuilder
  • StringBuilder class has been added in java 1.5 version.
  • StringBuilder having same features like StringBuffer class.
  • StringBuilder objects also mutable as StringBuffer
StringBuffer:
  1. Every method is synchronized.
  2. This object is thread safe, because it can access only one thread at a time.
  3. Low performance.
  4. Introduced in 1.0 version.
StringBuilder:
  1. No method is synchronized
  2. This object is not thread safe, because it can access multiple threads simultaneously.
  3. High performance
  4. Introduced in java 1.5 version.
Example for Synchronization : Interview pattern
  • At a time one candidate is allowed to attempt the interview in interview panel.
Thanks for your time.
Nireekshan