title: How do I search for equal elements that appear next to each other in an array
body: <p>I'm trying to write a method that will accept an array and find any equal elements that appear next to each other and return a count for the greatest number of occurances. For example an array with the int values of {1,2,3,4,4,4,5,6} would return a value of 3. An array with <code>{1,1,1,2,2,3,3,3,3,5,6,7}</code> would return a value of four. I've tried a few different ways, but I'm struggling. Any help would be appreciated. Thanks. Heres the code that I have so far-</p>
  
  <pre><code>public class EqualElements 
  {
      public static void consecutiveEqualElements(int [] elements)
      {
          int occurances = 0;
          int temp = 0;
          int count = 0;
  
          for (int index = 0; index &lt; elements.length; index++)
          {                   
              if(elements[index] == elements[temp])
              {
                  count++;
                  temp++;
                  index--;
              }
              else
              {       
              }
          }
          System.out.println(count);
      }
  
      public static void main(String[] args) 
      {
          int [] numbers = {1,2,2,3,4,5,6,7};
          consecutiveEqualElements(numbers);
      }
  }
  </code></pre>