binarySearch
Searches the array or the range of the array for the provided element using the binary search algorithm. The array is expected to be sorted according to the specified comparator, otherwise the result is undefined.
If the array contains multiple elements equal to the specified element, there is no guarantee which one will be found.
Since Kotlin
1.0Return
the index of the element, if it is contained in the array within the specified range; otherwise, the inverted insertion point (-insertion point - 1). The insertion point is defined as the index at which the element should be inserted, so that the array (or the specified subrange of array) still remains sorted according to the specified comparator.
Parameters
the element to search for.
the comparator according to which this array is sorted.
the start of the range (inclusive) to search in, 0 by default.
the end of the range (exclusive) to search in, size of this array by default.
Throws
Searches the array or the range of the array for the provided element using the binary search algorithm. The array is expected to be sorted, otherwise the result is undefined.
If the array contains multiple elements equal to the specified element, there is no guarantee which one will be found.
Since Kotlin
1.0Return
the index of the element, if it is contained in the array within the specified range; otherwise, the inverted insertion point (-insertion point - 1). The insertion point is defined as the index at which the element should be inserted, so that the array (or the specified subrange of array) still remains sorted.
Parameters
the to search for.
the start of the range (inclusive) to search in, 0 by default.
the end of the range (exclusive) to search in, size of this array by default.