As jensgram says, these two statements are not equivalent. Two important rules:
Concatenation of string literals in code ends with a string constant, so these two operators are exactly equivalent (they will create the same bytecode):
String x = "foo" + "bar": String x = "foobar";
String constants are interned automatically; you do not need to do this explicitly
Now, this focuses on literals — do you actually call intern literals, or is your real use case somewhat different (for example, interning values obtained from a database that you often see)? If yes, please tell us more details.
EDIT: Okay, based on editing the question: it can save some memory if you end up storing the return value toAddress() somewhere, that it will remain in place for a long time, and you will end up in the same address several times. If this is not the case, internment is actually likely to make matters worse. I do not know for sure whether the interned strings will remain forever, but this is entirely possible.
It seems to me that this is unlikely to be a good use of internment, and most likely it will be worse. You mention that you are trying to save the space of the pergman - why do you think that interning there will help? Concatenated strings will not end up anyway, if I'm not mistaken.
source share