difference between string buffer and string builder

Difference between String, String Buffer and String Builder

 StringString BufferString Builder
StorageHeap area

String constant pool

Heap area


Heap area


objectsImmutable object created (fixed size)Mutable objects createdMutable objects created
memoryIf we change the value of string a lot of time it will allocate more memoryConsumes less memory (original object value change)Consumes less memory
Thread SafeNot thread safeAll methods are thread safe and it is a thread safeNon-synchronized methods and not thread safe
performanceslowFast as compared to stringFast as compared to string builder
useIf the date s not changing frequentlyData is changing frequentlyData 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.