title: How do you check if 4 different numbers in an array are equal to each other?
body: <p>This method is supposed to return true if four different numbers in the array are all equal. But whenever I try to run it with <code>4</code> equal numbers, I get an error that says:
  </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5<br>
    at Assignment4.containsFourOfaKind(Assignment4.java:93)<br>
    at Assignment4.main(Assignment4.java:16)</p>
  </blockquote>
  
  <pre class="lang-java prettyprint-override"><code>public static boolean containsFourOfaKind( int hand[] ){ 
      for (int i = 0; i &lt; 5; i++) {
          if (hand[i    ] == hand[i + 1] &amp;&amp;
              hand[i + 1] == hand[i + 2] &amp;&amp; 
              hand[i + 2] == hand[i + 3]
          ) {
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>How can I fix this?</p>