title: Sort ArrayList of custom Objects by property
body: <p>I read about sorting ArrayLists using a Comparator but in all of the examples people used <code>compareTo</code> which according to some research is a method for Strings.</p>
  
  <p>I wanted to sort an ArrayList of custom objects by one of their properties: a Date object
  (<code>getStartDay()</code>). Normally I compare them by <code>item1.getStartDate().before(item2.getStartDate())</code> so I was wondering whether I could write something like:</p>
  
  <pre><code>public class CustomComparator {
      public boolean compare(Object object1, Object object2) {
          return object1.getStartDate().before(object2.getStartDate());
      }
  }
  
  public class RandomName {
      ...
      Collections.sort(Database.arrayList, new CustomComparator);
      ...
  }
  </code></pre>