Duplicate :
|
Various binary search methods in java.util.Arrays compute the average of two positive indices (ints) like this: int mid = (low + high) >> 1; but if low + high overflows into negative territory, the result is negative, probably giving undefined results. An easy fix is the simple int mid = (low + high) >>> 1; although I have not tested whether this is enough to get sort + binary search to actually work properly on such gigantic arrays.
|