title: Comparator vs Apache BeanComparator
body: <p>Consider a simple class:</p>
  
  <pre><code>class Employee {
  
  String name;
  int sal;
  
  ....//getters and setters
  }
  </code></pre>
  
  <p>I can create a Comparator to sort on field name for example. </p>
  
  <pre><code>class EmpSortByName implements Comparator&lt;Employee&gt;{
  
   @Override
   public int compare(Employee e1, Employee e2){
    return e1.getName().compareTo(e2.getName());
   }
  }
  </code></pre>
  
  <p>However, looking at apache commons BeanComparator, sorting can be achieved in following way:</p>
  
  <pre><code>BeanComparator bc = new BeanComparator("name");
  Collections.sort(employeeList, bc);
  </code></pre>
  
  <p>Thus, by using BeanComparator, I can achieve sorting with minimal code. What are the trade offs between using Comparators and BeanComparators: in terms of performance, usage scenarios (multiple fields sort, other factors)?</p>
  
  <p>I also understand that to use BeanComparator, the beanutils jar has to be imported.</p>