static Comparator<Contact> DATE_DEBUT_COMPARATOR = new Comparator<Contact>() {
@Override
public int compare(Contact first, Contact second) {
return first.getDateDebut().compareTo(second.getDateDebut());
}
// Ascending order of debut date
};
static Comparator<Contact> DATEFIN_COMPARATOR = new Comparator<Contact>() {
@Override
public int compare(Contact first, Contact second) {
return second.getDateFin().compareTo(first.getDateFin());
}
// Descending order of fin date
};
Passing comprator to Collections Util, can find object with min debut date at first location of Arraylist
Collections.sort(contactList, DATE_DEBUT_COMPARATOR);
Similarly passing comprator to Collections Util, can find object with max fin date at first location of Arraylist
Collections.sort(contactList, DATE_FIN_COMPARATOR);
Comparatorclass. It has little to do with theContactclass anyway.