DateUtil { public static void sortByDate(List<String> expiryDates) { Collections.sort(expiryDates, (lhs, rhs) -> { Date date = parseString(lhs, SIMPLE_DATE_FORMAT); if (date != null) { return date.compareTo(parseString(rhs, SIMPLE_DATE_FORMAT)); } else { return 0; } }); } private  DateUtil(); static Date truncateTimeStampInDate(Date date); static Date addDayOfMonth(Date date, int difference); static Date minusDayOfMonth(Date date, int difference); static String formatDate(Date date); static String formatDateTime(Date date); static String formatDateWithoutYear(Date date); static String formatDateWithoutDay(Date date); static String formatDateWithShortMonthAndYear(Date date); static String formatDateWithLongMonthAndYear(Date date); static String formatDate(Date date, String format); static Date parseString(String string, String format); static Date parseString(String string, String format, String timeZone); static Date today(); static String convertDate(String date, String currentFormat, String expectFormat); static Date dateMinusMonth(Date current, int months); static void sortByDate(List<String> expiryDates); static Period generateRnRFormPeriodBy(Date generateDate); static Date generatePreviousMonthDateBy(Date date); static int calculateDateMonthOffset(Date earlierDate, Date laterDate); static DateTime cutTimeStamp(DateTime dateTime); static long calculateTimeIntervalFromNow(long lastSyncedTimestamp); static String formatExpiryDateString(List<String> expiryDates); static String uniqueExpiryDates(List<String> expiryDates, String existingDates); static List<String> addExpiryDates(List<String> expiryDates, String date); static String getMonthAbbrByDate(Date date); static int calculateMonthOffset(DateTime biggerTime, DateTime smallerTime); static Date getActualMaximumDate(Date date); static Bitmap createBarcode(String str); static final String DEFAULT_DATE_FORMAT; static final String DATE_FORMAT_ONLY_MONTH_AND_YEAR; static final String DATE_FORMAT_ONLY_MONTH_AND_YEAR_SHORT; static final String DATE_FORMAT_ONLY_MONTH_AND_YEAR_LONG; static final String SIMPLE_DATE_FORMAT; static final String DATE_TIME_FORMAT; static final String TIME_FORMAT; static final String DATE_FORMAT_ONLY_DAY_AND_MONTH; static final String TIME_FORMAT_WITHOUT_SECOND; static final String DB_DATE_FORMAT; static final String DATE_DIGIT_FORMAT_ONLY_MONTH_AND_YEAR; static final String ISO_BASIC_DATE_TIME_FORMAT; static final int DAY_PERIOD_END; static final String MOZ_TIME_ZONE; static final SimpleDateFormat DATE_FORMATTER; static final SimpleDateFormat DATE_TIME_FORMATTER; static final SimpleDateFormat DATE_FORMAT_NOT_DISPLAY_YEAR; static final SimpleDateFormat DATE_FORMAT_NOT_DISPLAY_DAY; static final SimpleDateFormat DATE_FORMAT_MONTH_AND_YEAR_SHORT; static final SimpleDateFormat DATE_FORMAT_MONTH_AND_YEAR_LONG; static final long MILLISECONDS_MINUTE; static final long MILLISECONDS_HOUR; static final long MILLISECONDS_DAY; static final Calendar CALENDAR_NOW; }
@Test public void shouldSortByDate() throws Exception { ArrayList<String> list = new ArrayList<>(); list.add("18/10/2017"); list.add("16/10/2016"); list.add("18/10/2016"); DateUtil.sortByDate(list); assertThat(list.get(0), is("16/10/2016")); assertThat(list.get(1), is("18/10/2016")); assertThat(list.get(2), is("18/10/2017")); }