I have a list of Date objects, and a target Date. I want to find the date in the list that\'s nearest to the target date, but only dates that are before the target date.
private Date getDateNearest(List dates, Date targetDate){
return new TreeSet(dates).lower(targetDate);
}
Doesn't require a pre-sorted list, TreeSort fixes that. It'll return null if it can't find one though, so you will have to modify it if that's a problem. Not sure of the efficency either :P