I have the following Java POJO, Start date
is a string:
POJO Object:
public class Schedule {
private String id;
private String startDate = "";
//const and getters and setters
}
I want to sort a list of these objects by the start date field:
Adding POJOS to list:
List<Schedule> schedules = new ArrayList<Schedule>();
Schedule s1 = new Schedule();
s1.setStartDate("2018-09-01T15:00:00+0000");
Schedule s2 = new Schedule();
s2.setStartDate("2018-09-15T15:00:00+0000");
schedules.add(s1);
schedules.add(s2);
I have tried writing a comparator
but it does not seem to work, is there a way of sorting strings
by date (earliest first)?
Edit: I am currently using Java 7