As you probably know, comparing Strings with == yields true only when both are the same
String instance.
When you have duplicate String literals in your code, they are resolved to a single String instance. That is the case for the various "String" in that code, they are the same instance.
In the first piece of code, method replace() returns a new String instance that is the result of applying that replacement on the original instance. You have two calls to replace() on the same original instance, yielding 2 new String instances with the results. The results are "equal" but not the same instance, therefore == yields false.
In the second piece of code, replace() finds nothing to replace, and so it returns the original String instance, not a new one. Both results are then the same original instance, so == yields true.
In the last piece, replace() returns a new instance. The literal "STring" and the result are equal() but they're separate instances. Therefore == yields false.
If it still doesn't make sense to you, make sure to learn how
Java works with Strings in general, literal Strings in particular, and the operator ==.