Java String, StringBuffer, StringBuilder
String
is immutable. When you try to change the value of
a String
, it actually creates a new String
object. StringBuffer
and StringBuilder
are
mutable, while StringBuilder
is thread-safe and
StringBuffer
is not.
BTW, String is not strictly immutable, one can change its value by the following way:
1 | String s = "abc"; |