title: How to show maximum same adjacent elements in an array in Java
body: <p>Im new to Java and i'm doing array sorting problems and i'm having difficulties with this problem. Searched for simmular or duplicate posts, but didn't seem to find any.</p>
  
  <p>The problem is "Find the most same, adjacent elements in an array and write them in to a new array".</p>
  
  <p>My question is. 
  <strong>How can i store most occurued adjacent elements in an array from another array ?</strong></p>
  
  <p>This is what I have comed up so far.</p>
  
  <pre><code>int[] arr= {2, 1, 1, 3, 3, 2, 2, 2, 2, 1 ,1}; //test array
  
  int counter=0;
  int i = 0;
  int length = arr.length;
  int[] resultArr=new int[length];
  
  
  
  for (i=1; i&lt;length; i++)
  
      {
     if (arr[i-1]==arr[i])
      {
       counter++;      // Counter to represent maximal adjacent occurred elem.
       resultArr[i] = arr[i]  //Writing elements in result array
      }
  
  
  
  
  
  } 
   System.out.println(counter);  
   System.out.println(resultArr);     
  </code></pre>
  
  <hr>
  
  <pre><code> Input: It is the test array "arr"
  
   Output 1 : Shoud be 4 representing the maximum of same adjacent elements ( i.e the 2's in the array )
   Output 2 : Must be an array that contains the 4 elements of the array ({2, 2, 2 ,2} )
  </code></pre>
  
  <p>My output is (directly from console)</p>
  
  <p>1<br>
  [I@6d06d69c</p>