title: How Set checks for duplicates? Java HashSet
body: <p>For the below code it outputs " 1 ". and second code outputs " 2 " I don't understand why this is happening. Is it because I am adding the same object? How should I achieve the desired output 2.</p>
  
  <pre><code>import java.util.*;
  public class maptest {
  public static void main(String[] args) {
      Set&lt;Integer[]&gt; set = new HashSet&lt;Integer[]&gt;();
      Integer[] t = new Integer[2];
      t[0] = t[1] = 1;
      set.add(t);
      Integer[] t1 = new Integer[2];
      t[0] = t[1] = 0;
      set.add(t);
      System.out.println(set.size());
  
     }
  }
  </code></pre>
  
  <p>Second Code:</p>
  
  <pre><code>import java.util.*;
  public class maptest {
  public static void main(String[] args) {
      Set&lt;Integer[]&gt; set = new HashSet&lt;Integer[]&gt;();
      Integer[] t = new Integer[2];
      t[0] = t[1] = 1;
      set.add(t);
      Integer[] t1 = new Integer[2];
      t1[0] = t1[1] = 1;
      set.add(t1);
      System.out.println(set.size());
  
      }
  }
  </code></pre>