title: How to get how many times an element occurs in ArrayList
body: <pre><code>    for(int i=0; i&lt;arr.size(); ++i){
          oc = Collections.frequency(arr, arr.get(i));
          System.out.print(oc + " "+ arr.get(i) +" ");
          arr.remove(i);
      }
  </code></pre>
  
  <p>The main idea is to output how many times every element in sequence occurs.
  For example </p>
  
  <pre><code>1 1 2 3 3 3 10 10
  </code></pre>
  
  <p>here the output is</p>
  
  <pre><code>2 1 1 2 3 3 2 10
  </code></pre>
  
  <p>It is like two ones, one element of two, 3 elements of 3, and 2 elements of 10.</p>
  
  <p>This is buggy, for example it is not working for this case</p>
  
  <pre><code>1 1 1 2 2 1 1 1 
  </code></pre>
  
  <p>What is wrong? Any other algorithms?</p>