鉴于以下声明,取自
this Oracle java教程,与类Collections的binarySearch()方法有关:
The return value is the same for both forms. If the List contains the
search key,its index is returned. If not,the return value is
(-(insertion point) – 1),where the insertion point is the point at
which the value would be inserted into the List,or the index of the
first element greater than the value or list.size() if all elements in
the List are less than the specified value.
为什么binarySearch()的返回值不仅返回负指数而不是负指数减1? (上面引用的粗体部分).
简而言之:为什么( – (插入点) – 1)而不仅仅是( – (插入点))?
提前致谢.