title: Comparing the sum of two ArrayLists of objects using 'compareTo'
body: <p>I need to write code that allows a user to compare 2 hands of cards to find out which has the most valuable ones over-all. I have a class for the Card objects which each have a value and then a class for the Hand objects, storing a number of cards as an ArrayList.</p>
  
  <p>The result needs to be answered by using the following code:  int comparison = hand1.compareTo(hand2); and so my code to solve this need to be in the compareTo method of the Hand class.</p>
  
  <p>I've started to do a for-each loop but it doesn't seem to recognise 'mouse' here as an ArrayList</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Collections;
  
  public class Hand implements Comparable&lt;Hand&gt; {
      private ArrayList&lt;Card&gt; hand = new ArrayList&lt;Card&gt;();
  
      public Hand(ArrayList hand) {
  
      }
  
      public void add(Card card) {
          hand.add(card);
      }
  
      public void print(){
          for (Card mouse : hand){
              System.out.println(mouse.toString());
          }
      }
  
      public void sort(){
          Collections.sort(hand);
      }
  
      public int compareTo(Hand mouse){
          int x = 0;
          int y = 0;
          for (Card moose : hand){
  
              x = x + moose.getValue();
          }
  
          for (Card house : mouse){ // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ERROR
  
              y = y + house.getValue();
          }
          if (x &gt; y){
              return 1;
          }
          return 0;
      }
  }
  </code></pre>
  
  <p>I get an error saying that mouse is not an Array. But surely if it's a 'Hand' then it will be an array? I know I'm doing something dumb here but I can't figure out what that is.</p>