title: Java function for comparing Arrays position for position?
body: <p>I recently started learning Java for fun but got stuck at the following problem:
  I have 2 arrays int[] that holds a representation of a poker hand. 
  Position 0 in the array tells if it is a straight flush and the number in there tells the value of the high card. Position 1 in the array tells if its for of a kind and the value of the card so 5 here means you have fourofakind in 5:s and so on.</p>
  
  <p>So I want to compare all player arrays first position 0 (for straight flush) and the player that has highest number wins.. if all have 0 or 2 or more player have equal numbers step to position 1 in the array and compare and so on.</p>
  
  <p>To simplify the code I tried to do a compare function that compares the hands of 2 players and returns if hand1 (in code array1) is higher than hand 2 (array 2)</p>
  
  <ul>
  <li>If H1 > H2 return 1</li>
  <li>If H1 &lt; H2 return -1</li>
  <li>If equal return 0</li>
  </ul>
  
  <p>I did do the following code (that doesn't work):</p>
  
  <pre><code>int isBetterHand(int[] array1, int[]array2){ //private
      if(array1.length &gt; array2.length){ throw new RuntimeException("arrayCompare got arrays of different length.");}
      int arrayLength = array1.length;
      for(int i = 0; i &lt; arrayLength; i++){
          if(array1[i] &gt; array2[i]){
              return 1;
          } else if(array1[i] &lt; array2[i]){
              return -1;
          } else {
              return 0;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>I figure in Java you cant write if array1[0] (comparator like &lt;, >, ==) array2[0]</p>
  
  <p>How do I fix the code above? Also is there a faster, better, smarter way to do this? The arrays are 26 numbers long. I need co compare max 8 arrays.</p>
  
  <p>Say I have 5 players left in game I could get a matrix like (I only type in first 5 positions:</p>
  
  <p>P1 0, 0, 0, 0, 0, ...
  P2 0, 0, 0, 0, 0, ...
  P3 0, 2, 0, 0, 0, ...
  P4 0, 0, 13, 3, 0, ...
  P5 0, 0, 0, 0, 14, ...</p>
  
  <p>In the ex above pos[0] means highcard in straightflush noone has that
  in pos[1] it shows P3 is the winner with four of a kind in 2:s
  ((pos[2]&amp;[3] shows P4 has full house K over 3 (but P3 4 of a kind is better...)))</p>
  
  <p>Edit: Just wow! I didn't expect answers this fast. Now its working like a charm.
  A BIG! thank you to all who helped me. </p>
  
  <p>I have to go more indepth on the suggestions for comparing the matrix of arrays but you guys pointed me in the right direction there. </p>