The "==" operator compares two physical objects in memory to see if they occupy the same location in RAM -- i.e., to see if they are
physically the same object. That won't be the case in your example; the two strings are being dynamically created by calling "replace", and each one will be a distinct object created just for that purpose. Their contents will be identical, but they'll be physically different.
The "equals" method, which every
Java object has, is meant to compare two objects for
equivalence. If you replaced the "==" line in your code with
you'd find that you'd get the results you expect. Two separate String objects are equivalent if they're the same length and include all the same characters in the same order.
So don't use "==" for comparing Strings; a wise man once compared this to the act of running with scissors.