I have the following TreeMap:
private Map<Date,WeekSchedule> weeks = new TreeMap<Date,WeekSchedule>();
And I need to remove all entries, whose date is before a given value.
What is the most efficient way to do this?
This is what I have so far:
public void removeWeeksBefore(Date monDate){
for (Map.Entry<Date, WeekSchedule> entry : weeks.entrySet()){
if(entry.getKey().before(monDate)){
weeks.remove(entry.getKey()); //This will destroy the iterator
}else{
return;
}
}
}
Date
comparable? Can you store this as aNavigableMap
? – DisinheritJava.util.Date
is compareable – Mariano