title: How to find duplicates in a java array?
body: <p>I'm trying to count how many duplicate items are in an array.</p>
  
  <p>Example:</p>
  
  <pre><code>[0, 2, 0] would return 2, [0, 0, 0] would return 3, [0, 1, 2] = 0
  </code></pre>
  
  <p>So far I have it working for when all three items are equal, but I'm not sure why it's returning one less than what it should for 2 items being the same.</p>
  
  <pre><code>    int equal = 0;
  
      for(int i = 0; i &lt; recent.length; i++) {
          for(int j = i; j &lt; recent.length; j++) {
              if(i != j &amp;&amp; recent[i].equals(recent[j])) {
                  equal++;
              }
          }
      }
  </code></pre>