use 'Collections.frequency' to get a count of instances given one value
<p>To simplify what I'm doing, let's use the example from <a href="http://learnfromexamples.com/how-to-find-the-occurrences-of-a-particular-element-in-an-arraylist-in-java/" rel="nofollow">learnfromexamples.com</a> that I modified a few bits.</p>

<pre><code>package test;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


class Employee {
        private String empno;
        private String empName;

        public Employee(String empno, String empName ) {
            this.empno = empno;
            this.empName = empName;
        }

        public String getEmpno() {
            return empno;
        }

        public void setEmpno(String empno) {
            this.empno = empno;
        }

        public String getEmpName() {
            return empName;
        }

        public void setEmpName(String empName) {
            this.empName = empName;
        }
        @Override
        public String toString() {
            return "Empno is "+ empno + " Empname is " + empName;
        }
        public Employee() {
            // TODO Auto-generated constructor stub
        }

        @Override
        public boolean equals(Object arg0) {
            // TODO Auto-generated method stub
            boolean flag = false;
            Employee employee = (Employee) arg0;
            if(null!= employee &amp;&amp; employee.getEmpName().equalsIgnoreCase(empName) &amp;&amp; employee.getEmpno().equalsIgnoreCase(empno)){
                flag = true;
            }
            return flag;
        }

    }


public class Test  {
    public static void main(String[] args) {

        List&lt;Employee&gt; empList = new ArrayList&lt;Employee&gt;();
        empList.add(new Employee("001", "Shidhar"));
        empList.add(new Employee("002", "Pathy"));
        empList.add(new Employee("003", "Sahana"));
        empList.add(new Employee("003", "Sahana"));
        empList.add(new Employee("004", "Sahana"));
        empList.add(new Employee("003", "Sahana"));

        //Get the occurrence of "new Employee("003", "Sahana")" from empLists
        //int sahanaCount = Collections.frequency(empList, new Employee("003"));
        //System.out.println("Count of sahana is : " +sahanaCount);

        Set&lt;Employee&gt; uniqueId = new HashSet&lt;Employee&gt;(empList);
        for (Employee emId : uniqueId) {
            System.out.println("The emp with id "+emId.getEmpno()+" was repeated: "
                    + Collections.frequency(empList, emId.getEmpName()));
        }

    }
}
</code></pre>

<p>Is it possible to use <code>Collections.frequency</code> to find frequency given one variable e.g. <code>Collections.frequency(empList,"Sahana");</code> that yields 4.</p>

<p>Another alternative is I can use HashMap to keep the count but let's say I'm impressed with <code>Collections.frequency</code> and try to use it.</p>