title: Java Array HashCode implementation
body: <p>This is odd.  A co-worker asked about the implementation of myArray.hashCode() in java.  I thought I knew but then I ran a few tests.  Check the code below.  The odd thing I noticed is that when I wrote the first sys out the results were different.  Note that it's almost like it's reporting a memory address and modifying the class moved the address or something.  Just thought I would share.</p>
  <pre><code>int[] foo = new int[100000];
  java.util.Random rand = new java.util.Random();
  
  for(int a = 0; a &lt; foo.length; a++) foo[a] = rand.nextInt();
  
  int[] bar = new int[100000];
  int[] baz = new int[100000];
  int[] bax = new int[100000];
  for(int a = 0; a &lt; foo.length; a++) bar[a] = baz[a] = bax[a] = foo[a];
  
  System.out.println(foo.hashCode() + &quot; ----- &quot; + bar.hashCode() + &quot; ----- &quot; + baz.hashCode() +  &quot; ----- &quot; + bax.hashCode());
  
  // returns 4097744 ----- 328041 ----- 2083945 ----- 2438296
  // Consistently unless you modify the class.  Very weird
  // Before adding the comments below it returned this:
  // 4177328 ----- 4097744 ----- 328041 ----- 2083945
  
  
  System.out.println(&quot;Equal ?? &quot; +
    (java.util.Arrays.equals(foo, bar) &amp;&amp; java.util.Arrays.equals(bar, baz) &amp;&amp;
    java.util.Arrays.equals(baz, bax) &amp;&amp; java.util.Arrays.equals(foo, bax)));
  </code></pre>