Explain about StringBuffer class ?


StringBuffer class is final class.
StringBuffer class is direct chaild class of Object class.
StringBuffer class implements Serializable, CharSequence.
StringBuffer class is mutable.
StringBuffer class is thread-safe.
StringBuffer class methods are synchronized.
StringBuffer class introduced in JDK1.0

 

Difference between StringBuffer & StringBuilder


StringBuffer:

  1. Every method present in StringBuffer is Synchronized

  2. At a time only one thread can operate on StringBuffer object. Hence StringBuffer is thread safe

  3. Relatively performance is low

  4. Introduced in 1.0v

StringBuilder:

  1. No method present in StringBuilder is Synchronized

  2. Multiple threads can operate on StringBuilder object. Hence StringBuilder is not thread safe

  3. Relatively performance is high

  4. Introduced in 1.5v