Most of the answers here are correct (processed by the compiler, + converted to .append () ...)
I wanted to add that everyone should take a look at the source code for String and add at some point, this is pretty impressive.
I suppose it came down to something like:
"a"+"b"+"c"
=
new String().append("a").append("b").append("c")
But then some kind of magic happens. It turns into:
- Create an array of strings of length 3
- copy a to the first position.
- copy b to second
- copy c to third
While most people believe that it will create "ab", then throw it away when it creates "abc". He really understands that he is attached and does some manipulation.
There is also a trick where, if you have the string "abc" and you request a substring that turns out to be "bc", they can share the same base array. You will notice that there is a start position, end position and a common flag.
In fact, if it is not used, it can extend the length of the string and copy the rest.
Now I'm just confused. Read the source code - it's pretty cool.
Bill k
source share