String concatenation with Java 8
In summary, Java 8 seems not to introduce new optimizations for String concatenation with the + operator. It means that using StringBuilder manually is still required for specific cases where the compiler or the JIT is not applying magic tricks. For instance, when lot of substrings are concatenated to a String variable defined outside the scope of a loop.
The reason for not optimizing automatically all String concatenations is still a bit obscure to me. Probably, too much information and efforts are required to handle all possible cases safely. After all, that's also a good point to make programmers think about what they write.
Read full article from String concatenation with Java 8
No comments:
Post a Comment