I have a list of objects that implement non-overlapping ranges, e.g.:
1 to 10
11 to 20
21 to 50
51 to 100
They provide min()
and max()
to retrieve those values.
I need a datastore to easily retrieve the right object, given a value that must be in its interval.
The easiest way I can think of is to create an ordered arraylist and simply traverse it until I found the correct interval. So in this case a lookup is done in O(N).
Are there more efficient data structures available in the standard Java library to do this task?