Using Collections.binarySearch() for predicate search (i.e., not complete match)
问题 I have a list of timestamps sorted in ascending order: List<Instant> timestamps = ...; // note: sorted in ascending order Now, given an input timestamp Instant inputTs , I want to find an entry t in timestamps that satisfies t.isBefore(inputTs) && inputTs.isBefore(t.plusMillis(SOME_CONSTANT)) , i.e., I am simply looking for a t such that inputTs lies within the bounds of some fixed-length duration starting at t . I acknowledge that there can theoretically be multiple such t s, so the search