title: How to count duplicate elements in ArrayList?
body: <p>I need to separate and count how many values in arraylist are the same and print them according to the number of occurrences.</p>
  
  <p>I've got an arraylist called digits :</p>
  
  <pre><code> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]
  </code></pre>
  
  <p>I created a method which separates each value and saves it to a new array.</p>
  
  <pre><code>public static ArrayList&lt;Integer&gt; myNumbers(int z) {
  
      ArrayList&lt;Integer&gt; digits = new ArrayList&lt;Integer&gt;();
      String number = String.valueOf(z);
      for (int a = 0; a &lt; number.length(); a++) {
          int j = Character.digit(number.charAt(a), 10);
          digits.add(j);
      }
      return digits;
  
  }
  </code></pre>
  
  <p>After this I've got a new array called numbers. I'm using sort on this array</p>
  
  <pre><code>Collections.sort(numbers);
  </code></pre>
  
  <p>and my ArrayList looks like this: </p>
  
  <pre><code>[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9]
  </code></pre>
  
  <p>It has:</p>
  
  <pre><code>2 times 0; 
  9 times 1;
  4 times 2;
  6 times 3;
  5 times 4;
  6 times 5;
  5 times 6;
  5 times 7;
  5 times 8;
  3 times 9;
  </code></pre>
  
  <p>I need to print out the string of numbers depend on how many are they
  So it suppose to look like this :
  1354678290</p>