title: Count occurrences of elements inside array? (Java)
body: <p>I have been working on trying to figure out this algorithm for about 6 hours now and can't seem to come up with a solution. I am trying to count the occurrences of elements inside an array and may two more separate arrays. One for the unique instances, and one for how many times these instances occurs. I found some other thinks on here about array lists and hashMaps, but I am only able to use arrays.</p>
  
  <p>For example, I have this array (already sorted):</p>
  
  <pre><code>{cats, cats, cats, dog, dog, fish}
  </code></pre>
  
  <p>I am trying to get make an array for the instances, so:</p>
  
  <pre><code>{cats, dog, fish}
  </code></pre>
  
  <p>And finally, how many times these instances occur:</p>
  
  <pre><code>{3, 2, 1}
  </code></pre>
  
  <p>Here is the code i have so far: </p>
  
  <pre><code>public void findArrs( String[] words )
  {
    int counter = 1;
    for(int i = 0; i &lt; words.length - 1; i++){
    if(!(words[i].equals(words[i+1]))){
    counter++; 
    }
   }
  
   String[] unique = new String[counter];
   int[] times = new int[counter];
  
   for(int i = 0; i &lt; words.length; i++){
  
     }    
  }
  </code></pre>
  
  <p>This is all the code I have after all my attempts. </p>