Most of the answers here are correct (it's handled by the compiler, + is converted to .append()...)
I wanted to add that everyone should take a look at the source code for String and append at some point, it's pretty impressive.
I believe it came down to something like:
"a"+"b"+"c"
=
new String().append("a").append("b").append("c")
But then some magic happens. This turns into:
- Create a string array of length 3
- copy a into the first position.
- copy b into the second
- copy c into the third
Whereas most people believe that it will create "ab", then throw it away when it creates "abc". It actually understands that it's being chained and does some manipulation.
There is also a trick where if you have the string "abc" and you ask for a substring that turns out to be "bc", they CAN share the exact same underlying array. You'll notice that there is a start position, end position and "shared" flag.
In fact, if it's not shared, it's possible for it to extend the length of a string and copy the others in.
Now I'm just being confusing. Read the source code--it's fairly cool.