String vs StringBuilder vs StringBuffer

String
String is immutable  ( once created can not be changed )object  . The object created as a String is stored in the  Constant String Pool  . They are thread safe.
StringBuffer

StringBuffer is mutable means one can change the value of the object . Object created through StringBuffer is stored in the heap. Each method in StringBuffer is synchronized that is StringBuffer is thread safe

StringBuilder

StringBuilder is same as the StringBuffer , that is it stores the object in heap and it can also be modified . StringBuilder is also not thread safe.

Leave a comment