title: Android - How to sort arrayList by date?
body: <p>I'm trying to sort my <code>arrayList</code> by date. I stored the date on Firebase each time I receive a notification and is retrieved from there. I'm using <code>Collections.sort</code> but I don't know how to implement onto my codes as my date format starts with a number in a string format like "12 Jul 2017 at 12:00am".  </p>
  
  <p>I've seen some examples of this on stackoverflow but I don't know how to make it work in my case. I will post screenshots and my codes below.</p>
  
  <p>The dates are not sorted.</p>
  
  <p><a href="https://i.stack.imgur.com/qolEQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qolEQ.jpg" alt="enter image description here"></a></p>
  
  <p><strong>NotificationFragment.java</strong></p>
  
  <pre><code>public class NotificationFragment extends Fragment {
          prepareNotification1();
          sortDate();
          return v;
      }
  
         private void prepareNotification1() {
              FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
              String userID = user.getUid();
  
    mRef.child("customers").child(userID).child("Notification").addChildEventListener(new ChildEventListener() {
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                      Notification menu = dataSnapshot.getValue(Notification.class);
                      notificationList.add(menu);
                  mAdapter.notifyDataSetChanged();
              }
   });
      }
  
      public void sortDate() {
          Collections.sort(notificationList, new Comparator&lt;Notification&gt;() {
              @Override
              public int compare(Notification lhs, Notification rhs) {
                  return lhs.getDate().compareTo(rhs.getDate());
              }
          });
          mAdapter = new NotificationAdapter(getContext(), notificationList);
          mRecyclerView.setAdapter(mAdapter);
      }
  }
  </code></pre>
  
  <p><strong>MyFirebaseMessagingService.java</strong></p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          Calendar cal = Calendar.getInstance();
  
          String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
  
          SimpleDateFormat df = new SimpleDateFormat("hh:mm a");
          String currentTime = df.format(cal.getTime());
  
          String notificationTime = currentDateTimeString + " at " + currentTime;
  
          Notification newNotification = new Notification(remoteMessage.getData().get("body"), notificationTime);
          mRef.child("customers").child(userID).child("Notification").push().setValue(newNotification);
  }
  </code></pre>
  
  <p><strong>Notification.java</strong></p>
  
  <pre><code>public class Notification {
      private String message;
      private String date;
  
  
      public Notification(){
      }
  
      public Notification(String message, String date){
          this.message = message;
          this.date = date;
      }
  
      public String getDate() {
          return date;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  
      public String getMessage() {
          return message;
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  }
  </code></pre>