daniel
daniel

Reputation: 585

How do I have the nearest element to a certain element in a set?

Let say that I have a set as so:

Set<DueDate> dueDates;

class DueDate{
     Date date;
}

I need to find the nearest date element that comes right after a specified date.

The set contains around a 1000 entries. Is it ok if I just iterate over the set to find the nearest date entry or I have to use some type of sort or data structure to do it in a more efficient way.

Upvotes: 0

Views: 50

Answers (1)

erickson
erickson

Reputation: 269857

TreeSet is a NavigableSet implementation. Your requirements are not precise, so I'm not sure if you are looking for the higher() (strictly greater) or ceiling() (greater or equal) method, but one of those should meet your needs.

Upvotes: 1

Related Questions