As you said internally, the last concatenation is done with something similar to
String e = new StringBuilder().append(c).append("ender").toString();
the implementation of toString() StringBuilder creates a new line . Here is the implementation.
public String toString() {
Comparing strings using == instead of .equals() returns true only if both strings are the same . In this case, they do not match, since the second string is created as a new object of type String .
Other concatenations are performed directly by the compiler, so no new String is created.
Davide Lorenzo MARINO Dec 29 '15 at 11:04 2015-12-29 11:04
source share