 <blockquote> <p>do all JVMs optimize the usage of Strings in a way such that when the same string is used several times, it will always be the same physical instance?</p> </blockquote> <p>I doubt that very much. In the same class file, when definined like:</p> <pre><code>String s1 = "Yes"; String s2 = "Yes"; </code></pre> <p>you'll probably have s1 == s1.</p> <p>But if you have like:</p> <pre><code>String x = loadTextFromFile(); // file contains es StringBuilder b = new StringBuilder(); s2 = b.append("Y").append(x).toString(); // s2 = "Yes" </code></pre> <p>I don't think the runtime is going to check and compare all the loaded strings to the return value of them builder. </p> <p>So, always compare objects with equals(). That's good advice anyway since every good equals starts with:</p> <pre><code>if (this == o) { return true; } </code></pre>