Concept

How does string concatenation work in Java?

ComputerScienceOne / String Methods

"Java has a concatenation operator built into the language. The familiar plus sign, +, can be used to combine one or more strings by appending them to each other. Concatenation results in a new string. String firstName = \"Tom\"; String lastName = \"Waits\"; String formattedName = lastName + \", \" + firstName; //formattedName now contains \"Waits, Tom\". Concatenation also works with numeric types and even objects. int x = 10; double y = 3.14; String s = \"Hello, x is \" + x + \" and y = \" + y; //s contains \"Hello, x is 10 and y = 3.14\". When used with objects, the concatenation operator internally invokes the object's toString() method. The plus operator as a concatenation operator is syntactic sugar. When the code is compiled, it is replaced with equivalent code that uses a series of the StringBuilder class's append() method. StringBuilder is a mutable version of the String class."

Related Ideas

How does string concatenation work in Java? | ComputerScienceOne | Bifalgorithm | Bifalgorithm