I saw this question and some similar and I think it's not duplicate :
StringBuilder vs String concatenation in toString() in Java
Here is the deal, I hear a very clever work colleague of mine talking this morning about how java optimizes up to 8 or 16 string concatenation(I'm not sure at this point) to string builder. Because this might have been a vague description of what I mean here is an example of 6 String concatenation :
public String test(){
return "a" + "b" + "c" + "d" + "e" + "f";
}
So that this is actually translated to :
public String test(){
StringBuilder sb = new StringBuilder();
return sb.append("a").append("b").append("c").append("d").append("e").append("f").toString();
}
I had to leave the conversation earlier, is this true?If yes can someone provide more details of exact number up to when this optimization is done 8/16 or x?
I didn't know about this before I've heard it. good to know if true.