I am having troubles comparing dates as strings. I am required to iterate through a collection and compare the date value of each object against 2 dates passed as parameters. The dates are all stored as strings and am required to keep them that way.
It is known that the dates will all be formatted YYYY-MM-DD. Below is a quick example of what I mean. Thanks all!
public ArrayList<Object> compareDates(String dateOne, String dateTwo) {
for(Object object : objectCollection) {
String objectDate = object.getDate();
if(objectDate.equals(dateOne) || objectDate.equals(dateTwo)) { // Unsure of how to determine if the objects date is inbetween the two given dates
//add object to collection
}
}
return collection;
}
Strings, then split them by"-"and compare the separated values. You may have to cast them tointthen...SimpleDateFormatto make concreteDateobjects out of your string and compare these.objectCollectionvariable. Like @Stultuske said, why compare them as streings? You can parse them in toCalendars orDates which are comparable.