| ▲ | masklinn a day ago | |
> As noted a paragraph later, the Java compiler is able to detect and “fix” this, by rewriting the code to use a mutable string. Does it actually do that nowadays? Back in my days it was incapable of lifting the builder out of loops, so for each iteration it would instantiate a builder with the accumulator string, append the concatenation, then stringify and reset the accumulator. The linked docs don’t say anything about loops. | ||
| ▲ | emil-lp a day ago | parent [-] | |
I agree. If you append to a string in a loop in Java, you will see quadratic behavior. | ||