title: How to sort objects according to string date in java
body: <p>I am creating an android application where I need to sort objects according to date. The date is stored as a <code>String</code> in Customer Object. How can I do it?</p>
  
  <p>I have already tried it using the <code>Collection.sort()</code> method but with no success.</p>
  
  <pre><code>public static Comparator&lt;Customer&gt; dateNewOld = new Comparator&lt;Customer&gt;() {
         @Override
         public int compare(Customer o1, Customer o2) {
             DateFormat f = new SimpleDateFormat("dd/MM/yyyy");
             try
             {
                 return f.parse(o2.date).compareTo(f.parse(o1.date));
             }
             catch (ParseException e)
             {
                 e.printStackTrace();
             }
             return 0;
         }
     };
  </code></pre>
  
  <p>I expect the output to be sorted ArrayList but it doesn't get sorted according to date.</p>
  
  <p>My Date Format is <code>19.Jul.2019</code>, but it’s giving me Unparseable Exception.</p>