difference between string buffer and string builder

Difference between String, String Buffer and String Builder

  String String Buffer String Builder
Storage Heap area

String constant pool

Heap area

 

Heap area

 

objects Immutable object created (fixed size) Mutable objects created Mutable objects created
memory If we change the value of string a lot of time it will allocate more memory Consumes less memory (original object value change) Consumes less memory
Thread Safe Not thread safe All methods are thread safe and it is a thread safe Non-synchronized methods and not thread safe
performance slow Fast as compared to string Fast as compared to string builder
use If the date s not changing frequently Data is changing frequently Data is changing frequently

 

String constant pool :  it s a special memory location is heap area which stores string literals.

Immutable objects : the string objects are created immutable the value should not be changed it is fixed memory.