title: hashCode() for an array of objects for use in HashMap
body: <p>I Have the following two classes and want to use <code>Foo1</code> as keys in a <code>HashMap</code>.  Two <code>Foo1</code> objects are equal if their <code>Foo2</code> objects are equal, and <code>Foo2</code> objects are equal if their byte arrays satisfy <code>Arrays.equals()</code>. </p>
  
  <p>I am not quite sure what to do for the <code>hashCode()</code> method for <code>Foo1</code>.  Do I just need to sum up the hashcodes from each of its <code>Foo2</code> objects or is this inefficient?</p>
  
  <pre><code>public class Foo1 {
  
    Foo2[] foo2_array;
  
    @Override
    public boolean equals(Object Other) {
  
       for (int i = 0; i &lt; foo2_array.length; i++) {
  
          if (!foo2_array[i].equals(other.foo2_array[i])
            return false;
       }
  
       return true;
     }
  
     @Override
     public int hashCode() {
  
        // what to here?
     }
  }
  
  public class Foo2 {
  
    byte[] values;
  
    @Override
    public boolean equals(Object other) {
  
        return Arrays.equals(values, other.values);
    }
  
    @Override
    public int hashCode() {
  
       return Arrays.hashCode(values);
    }
  }
  </code></pre>