The return value is "StrinG", which is not in the String pool
So therefore the return value for each method call returns a new seperate object on the heap
why each method call returns a new seperate object on the heap other than in the string pool?
Mark Spritzler, could you explain it
thanks in advance !
I could be wrong on this, but whenever you run replace on a string, and a modified string results, a new string is created (even if it has the same character sequence as a string in the pool) and consequently has a different address. If however a resulting string from a string function (eg. replace, trim) is the same as the original string, then no new string is created and the resulting string just points back to the original interned string.