Join the DZone community and get the full member experience.Join For Free
1. + operator. The + operator does string concatenation as soon as one of its operands is a string. Then the other operand is converted to string. Example:
> "Say hello " + 7 + " times fast!" ’Say hello 7 times fast!’Alternatively, you can use += where
a += bis an abbreviation for
a = a + bExample:
> var str = ""; > str += "Say hello "; ’Say hello ’ > str += 7; ’Say hello 7’ > str += " times fast!"; ’Say hello 7 times fast!’
2. Joining an array of strings. Collect the strings to be concatenated in an array and join it afterwards.
- “Ropes: an Alternative to Strings (1995)” by Hans-J. Boehm , Russ Atkinson , Michael Plass.
Opinions expressed by DZone contributors are their own.