title: How to count the number of occurrences of an element in a List
body: <p>I have an <code>ArrayList</code>, a Collection class of Java, as follows:</p>
  
  <pre><code>ArrayList&lt;String&gt; animals = new ArrayList&lt;String&gt;();
  animals.add("bat");
  animals.add("owl");
  animals.add("bat");
  animals.add("bat");
  </code></pre>
  
  <p>As you can see, the <code>animals</code> <code>ArrayList</code> consists of 3 <code>bat</code> elements and one <code>owl</code> element. I was wondering if there is any API in the Collection framework that returns the number of <code>bat</code> occurrences or if there is another way to determine the number of occurrences.</p>
  
  <p>I found that Google's Collection <code>Multiset</code> does have an API that returns the total number of occurrences of an element. But that is compatible only with JDK 1.5. Our product is currently in JDK 1.6, so I cannot use it.</p>