title: Find most common Object from a list
body: <p>Let's say I have a <code>List</code> of <code>Employee</code> Objects. The <code>Employee</code> Objects have a <code>getDepartment</code> method which returns a <code>Department</code> Object. I want to iterate through that list to find the department with the most <code>Employee</code>s (i.e. the <code>Department</code> Object returned most often from <code>getDepartment</code>). What is the fastest way to do this?</p>
  
  <pre><code>public class Employee{
  
     static allEmployees = new ArrayList&lt;Employee&gt;();       
  
     int id;
     Department department;
  
     public Employee(int id, Department department){
       this.id = id;
       this.department = department;
       allEmployees.add(this);
     }
  
     public Department getDepartment(){
       return department;
     }
  
     public static List&lt;Employee&gt; getAllEmployees(){
        return allEmployees;
     }
  }
  
  public class Department{
     int id;
     String name;
  
     public Department(int id){
       this.id = id;
     }
  
     public String getName(){
       return name;
     }
  }
  </code></pre>
  
  <p>If there's two departments with an equal number of employees it doesn't matter which is returned.</p>
  
  <p>Thanks!</p>