title: What's the difference between ".equals" and "=="?
body: <p>I switched lecturers today and he stated using a weird code to me. (He said it's better to use <code>.equals</code> and when I asked why, he answered "because it is!")</p>
  
  <p>So here's an example:</p>
  
  <pre><code>if (o1.equals(o2))
  {
   System.out.println("Both integer objects are the same");
  }
  </code></pre>
  
  <p>Instead of what I'm used to:</p>
  
  <pre><code>if (o1 == o2)
  {
    System.out.println("Both integer objects are the same");
  }
  </code></pre>
  
  <p>What's the difference between the two. And why is his way (using <code>.equals</code>) better?</p>
  
  <p><a href="http://www.javabeat.net/qna/13-what-is-difference-between-equals-and-/" rel="noreferrer">Found this</a> on a quick search but I can't really make sense of that answer:</p>