i want to sort the list of task,first by date and then by taskID below is the code
ArrayList<fullist> taskdet = new ArrayList<fullist>();
public static class fullist
{
public int date;
public int id;
public fullist(int id, int date) {
this.date = date;
this.id = id;
}
}
i used the Collections.sort method to sort but through this i can sort either by date or ID at a time. if sort by date
Collections.sort(taskdet, new Comparator<fullist>() {
@Override
public int compare(fullist o1, fullist o2) {
//if(o1)
return Integer.compare(o1.date, o2.date);
}
});
This is the output displayed :
day 19 ID 2
day 19 ID 1
day 19 ID 3
day 20 ID 2
day 20 ID 1
day 20 ID 3
if sort by ID.
Collections.sort(taskdet, new Comparator<fullist>() {
@Override
public int compare(fullist o1, fullist o2) {
//if(o1)
return Integer.compare(o1.date, o2.date);
}
});
This is the output displayed :
day 20 ID 1
day 19 ID 1
day 19 ID 2
day 20 ID 2
day 20 ID 3
day 19 ID 3
but output should be :
day 19 ID 1
day 19 ID 2
day 19 ID 3
day 20 ID 1
day 20 ID 2
day 20 ID 3