title: Comparing two arrays in java and return number of equalities
body: <p>I'm currently writing a small function which should return how many items of an array are exactly on the same position as the other array and how many are there but on different positions.</p>
  
  <p>the function currently looks like this:</p>
  
  <pre><code>public static int[] numCorrects(char[] leftarray, char[] rightarray){
      int counter[] = new int[2];
      counter[0] = 0;
      counter[1] = 0;
  
      for (int i = 0; i &lt; leftarray.length; i++) {
          if(leftarray[i]==rightarray[i]) counter[0]++;
          else {
              for (int n = 0; n &lt; leftarray.length; n++) {
                  if (leftarray[i] == rightarray[n] &amp;&amp; leftarray[n] != rightarray[n]) {
                      counter[1]++;
                      break;
                  }
              }
          }
      }
      return counter;
  }
  </code></pre>
  
  <p>This works kinda well if i have lets say the <code>leftarray</code> of <code>(1, 2, 3, 4)</code> and the <code>rightarray</code> of <code>(4, 3, 2, 2)</code></p>
  
  <p>it the returns <code>(0, 3)</code> (0 exact match, 3 there but on different position)</p>
  
  <p>but now the problem:</p>
  
  <p>if I swap the inputs with <code>leftarray</code> of <code>(4, 3, 2, 2)</code> and <code>rightarray</code> of <code>(1, 2, 3, 4)</code> the output is <code>(0, 4)</code> which is wrong (should be the same as the 1st one)</p>
  
  <p>hope anyone can help me. thx</p>