String
is immutable
i.e. strings cannot be altered. When you alter a string (by adding to it for example), you are actually creating a new string.
But StringBuilder
is not immutable (rather, it is mutable)
so if you have to alter a string many times, such as multiple concatenations, then use StringBuilder
.