Yeah, i actually did two variations of this before realizing that either of them required at least one iteration of all the values in the set before picking the nearest value. TreeSet does not have binary search build-in, so creating a list of all the values just to support the binary binary search seems inefficient.

The current implementation iterates through the set values starting from the smallest one, but as the iterator guarantees ascending order we can break after the first bigger value is met.