Methods For concat Strings
Contents
Using +
When one of the left and right variables is of type String
, the plus method can be used to convert the two variables into strings and concatenate them.
|
|
Using concat()
When two variables are both String
and both not null, it can be used.
|
|
Using append()
(recommend)
When there are more than two Strings, we can consider using this method, to avoid creating temporary string variable.
|
|
we can also set an estimated capacity when instantiating the StringBuilder
Class to reduce performance overhead from expanding buffer space.
|
|
!! The +
concatenation of strings in Java is implemented by using append()
!! So, using StringBuilder
is more efficient.