title: How to get a unique hashCode for an ArrayList?
body: <pre><code>var arr1 = new ArrayList&lt;Integer&gt;();
  var arr2 = new ArrayList&lt;Integer&gt;();
  
  System.out.println(arr1.hashCode());
  System.out.println(arr2.hashCode());
  System.out.println(arr1.equals(arr2));
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1
  1
  true
  </code></pre>
  
  <p>After searching, I found <a href="https://stackoverflow.com/a/35702670/9140652">this answer</a> which explains why this is happening.</p>
  
  <p>From the answer:</p>
  
  <blockquote>
    <p>Here's the Java 8 implementation (it's actually implemented in
    <code>AbstractList</code>) :</p>
  
  <pre><code>public int hashCode() {
      int hashCode = 1;
      for (E e : this)
          hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
      return hashCode;
  }
  </code></pre>
  </blockquote>
  
  <p>And since the two arrays are empty, it's obvious that the <code>hashCode</code> function would return <code>1</code> for both of the arrays. </p>
  
  <p>My question is, given two <code>ArrayLists</code>, how to determine whether they are the same or not? How can I be sure that modifing one <code>ArrayList</code> won't affect the other? since I have no unique hash for each <code>ArrayList</code>, I can't compare their hashes to know whether they're equal or not. How to get a unique hash for each object?</p>
  
  <p>Also why the <code>equals</code> function returns <code>true</code>? Does it compare objects by hashes? Are they actually the same object? If yes then why and how to make different objects then?</p>
  
  <p>And what are the classes other than <code>ArrayList</code> that acts in this way?</p>