Good question.
public
String replace(char oldChar,
char newChar);
a) - If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned.
b) - If oldChar and newChar are identical then a reference to this String object is returned.
c)Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar
In first case you invoke "String".replace('t', 't'), Here since oldChar and newChar in call to replace are identical a reference to exisinting "String" object is returned. Further since "String" is a literal that is used in your code , and as you know Strings are immutable and hence JVM the following will happen.
a. JVM will create a new String object in String pool for the string literal used in your code.
b. Due to above explanation , replace() will return the this string object and since this string object ["String"] is already in the String pool a reference to it is returned and hence the result is equal in first case.
Now coming to second case since oldChar and newChar are different in both the calls to replace a new string object is created in both the cases even though the final string is same. The JAVADOC API says that a new string object will be created.
Hope this clears
good one.