title: Comparing 2 strings in Java
body: <p>I have two <code>String</code>s, for example:</p>
  
  <pre><code>s1=abcd
  s2=abfg
  </code></pre>
  
  <p>I want to compare these two <code>String</code>s and print the starting <code>String</code> until they are different. For instance, I want to print <code>ab</code> in this case. How can I get this result?</p>