Friday, 9 December 2016

String Buffer vs String Builder

In Java, these are the difference between String, String Builder and String Buffer:

StringString BufferString Builder
Immutable (cannot be changed after creation)Mutable (can be changed after creation)Mutable (can be changed after creation)
Thread Safe (Can be used across threads)Thread Safe (Can be used across threads)Not thread safe
Performance is goodPerformance is slow due to synchronized overheadPerformance is good
'+' operation can be used in String to add two strings'+' operation is not allowed'+' operation is not allowed
Stored in constant String poolStored in Heap area of memoryStored in Heap area of memory

No comments:

Post a Comment