title: Getting the count of duplicate values in arrayList in Java without affecting the order of arrayList
body: <p>I am trying to get the count of duplicate values of <code>String ArrayList</code>, i have achieved the task but not completely. i am able to get the <code>counts</code> of duplicate <code>elements</code> of my <code>arrayList</code>, but the problem is that the <code>order</code> of <code>arrayList</code> destroys when i get the <code>occurrences</code> of <code>elements</code></p>
  
  <p>here is my <code>code</code>:</p>
  
  <pre><code>    Map&lt;String, Integer&gt; counts = new HashMap&lt;String, Integer&gt;();
  
      for (String str : t.courseName) {
          if (counts.containsKey(str)) {
              counts.put(str, counts.get(str) + 1);
          } else {
              counts.put(str, 1);
          }
      }
  
      for (Map.Entry&lt;String, Integer&gt; entry : counts.entrySet()) {
          System.out.println(entry.getKey() + " = " + entry.getValue());
      }
  </code></pre>
  
  <p>this code works fine for getting <code>occurrences</code> but note that this code destroys the <code>order</code>. what i want is that the <code>order</code> should also not be destroyed. </p>