binarySearch

Performs a search on sorted array arr.
If arr is not sorted, results are undefined.
Implicitly, this assumes that all objects are Comparable.

Parameters:

arr - the array to search.

x - the object to search for.

Returns:

if x is found, returns the index where it is found.
otherwise, x is not found. In that case, a negative
number is always returned, and this number is equal
to -( p + 1 ), which p is the first position greater
than x. This can range from -1 down to -(arr.length+1).

binarySearch

Performs a search on sorted array arr using a comparator.
If arr is not sorted, results are undefined.

Parameters:

arr - the array to search.

x - the object to search for.

cmp - the comparator.

Returns:

if x is found, returns the index where it is found.
otherwise, x is not found. In that case, a negative
number is always returned, and this number is equal
to -( p + 1 ), which p is the first position greater
than x. This can range from -1 down to -(arr.length+1).