Thursday, February 18, 2016

Difference between String, String Buffer and String Builder

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

String String Buffer String 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 good Performance is slow due to synchronized overhead Performance is good
'+' operation can be used in String to add two strings '+' operation is not allowed '+' operation is not allowed
Stored in constant String pool Stored in Heap area of memory Stored in Heap area of memory


No comments:

Post a Comment