title: Sorting ArrayList of objects with two properties
body: <p>I am using JDK 1.7 for my project. I have come across Huddle. I have an ArrayList of objects which have two properties: price (decimal) and product name (String). I need to sort the ArrayList, first by price and then by product name. I've tried to use the Java comparator, but I can only sort by one property.
  Here is my code:</p>
  
  <pre><code>private static class PriceComparator implements Comparator&lt;Product&gt;{
   @Override
   public int compare(Product p1, Product p2) {
      return (p1.getPrice() &gt; p2.getPrice() ) ? -1: (p1.getPrice() &lt; p2.getPrice()) ?   
    1:0 ;
   }
  </code></pre>
  
  <p>}</p>
  
  <p>This code only sort price, and not name.</p>
  
  <p>Please i would apprecaite your help and example.</p>
  
  <p>Thanks
  Ish</p>