Condividi tramite


Arrays.BinarySearch Method

Definition

Overloads

BinarySearch(Object[], Int32, Int32, Object, IComparator)

Searches a range of the specified array for the specified object using the binary search algorithm.

BinarySearch(Single[], Int32, Int32, Single)

Searches a range of the specified array of floats for the specified value using the binary search algorithm.

BinarySearch(Int64[], Int32, Int32, Int64)

Searches a range of the specified array of longs for the specified value using the binary search algorithm.

BinarySearch(Int32[], Int32, Int32, Int32)

Searches a range of the specified array of ints for the specified value using the binary search algorithm.

BinarySearch(Int16[], Int32, Int32, Int16)

Searches a range of the specified array of shorts for the specified value using the binary search algorithm.

BinarySearch(Char[], Int32, Int32, Char)

Searches a range of the specified array of chars for the specified value using the binary search algorithm.

BinarySearch(Byte[], Int32, Int32, SByte)

Searches a range of the specified array of bytes for the specified value using the binary search algorithm.

BinarySearch(Object[], Int32, Int32, Object)

Searches a range of the specified array for the specified object using the binary search algorithm.

BinarySearch(Double[], Int32, Int32, Double)

Searches a range of the specified array of doubles for the specified value using the binary search algorithm.

BinarySearch(Single[], Single)

Searches the specified array of floats for the specified value using the binary search algorithm.

BinarySearch(Int64[], Int64)

Searches the specified array of longs for the specified value using the binary search algorithm.

BinarySearch(Int32[], Int32)

Searches the specified array of ints for the specified value using the binary search algorithm.

BinarySearch(Int16[], Int16)

Searches the specified array of shorts for the specified value using the binary search algorithm.

BinarySearch(Double[], Double)

Searches the specified array of doubles for the specified value using the binary search algorithm.

BinarySearch(Char[], Char)

Searches the specified array of chars for the specified value using the binary search algorithm.

BinarySearch(Byte[], SByte)

Searches the specified array of bytes for the specified value using the binary search algorithm.

BinarySearch(Object[], Object)

Searches the specified array for the specified object using the binary search algorithm.

BinarySearch(Object[], Object, IComparator)

Searches the specified array for the specified object using the binary search algorithm.

BinarySearch(Object[], Int32, Int32, Object, IComparator)

Searches a range of the specified array for the specified object using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;IILjava/lang/Object;Ljava/util/Comparator;)I", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static int BinarySearch (Java.Lang.Object[] a, int fromIndex, int toIndex, Java.Lang.Object? key, Java.Util.IComparator? c);
[<Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;IILjava/lang/Object;Ljava/util/Comparator;)I", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member BinarySearch : Java.Lang.Object[] * int * int * Java.Lang.Object * Java.Util.IComparator -> int

Parameters

a
Object[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Object

the value to be searched for

c
IComparator

the comparator by which the array is ordered. A null value indicates that the elements' Comparable natural ordering should be used.

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches a range of the specified array for the specified object using the binary search algorithm. The range must be sorted into ascending order according to the specified comparator (as by the #sort(Object[], int, int, Comparator) sort(T[], int, int, Comparator) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements equal to the specified object, there is no guarantee which one will be found.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(T[], int, int, T, java.util.Comparator<? super T>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Single[], Int32, Int32, Single)

Searches a range of the specified array of floats for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([FIIF)I", "")]
public static int BinarySearch (float[] a, int fromIndex, int toIndex, float key);
[<Android.Runtime.Register("binarySearch", "([FIIF)I", "")>]
static member BinarySearch : single[] * int * int * single -> int

Parameters

a
Single[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Single

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array of floats for the specified value using the binary search algorithm. The range must be sorted (as by the #sort(float[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(float[], int, int, float).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Int64[], Int32, Int32, Int64)

Searches a range of the specified array of longs for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([JIIJ)I", "")]
public static int BinarySearch (long[] a, int fromIndex, int toIndex, long key);
[<Android.Runtime.Register("binarySearch", "([JIIJ)I", "")>]
static member BinarySearch : int64[] * int * int * int64 -> int

Parameters

a
Int64[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Int64

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array of longs for the specified value using the binary search algorithm. The range must be sorted (as by the #sort(long[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(long[], int, int, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Int32[], Int32, Int32, Int32)

Searches a range of the specified array of ints for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([IIII)I", "")]
public static int BinarySearch (int[] a, int fromIndex, int toIndex, int key);
[<Android.Runtime.Register("binarySearch", "([IIII)I", "")>]
static member BinarySearch : int[] * int * int * int -> int

Parameters

a
Int32[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Int32

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array of ints for the specified value using the binary search algorithm. The range must be sorted (as by the #sort(int[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(int[], int, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Int16[], Int32, Int32, Int16)

Searches a range of the specified array of shorts for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([SIIS)I", "")]
public static int BinarySearch (short[] a, int fromIndex, int toIndex, short key);
[<Android.Runtime.Register("binarySearch", "([SIIS)I", "")>]
static member BinarySearch : int16[] * int * int * int16 -> int

Parameters

a
Int16[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Int16

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array of shorts for the specified value using the binary search algorithm. The range must be sorted (as by the #sort(short[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(short[], int, int, short).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Char[], Int32, Int32, Char)

Searches a range of the specified array of chars for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([CIIC)I", "")]
public static int BinarySearch (char[] a, int fromIndex, int toIndex, char key);
[<Android.Runtime.Register("binarySearch", "([CIIC)I", "")>]
static member BinarySearch : char[] * int * int * char -> int

Parameters

a
Char[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Char

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array of chars for the specified value using the binary search algorithm. The range must be sorted (as by the #sort(char[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(char[], int, int, char).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Byte[], Int32, Int32, SByte)

Searches a range of the specified array of bytes for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([BIIB)I", "")]
public static int BinarySearch (byte[] a, int fromIndex, int toIndex, sbyte key);
[<Android.Runtime.Register("binarySearch", "([BIIB)I", "")>]
static member BinarySearch : byte[] * int * int * sbyte -> int

Parameters

a
Byte[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
SByte

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array of bytes for the specified value using the binary search algorithm. The range must be sorted (as by the #sort(byte[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(byte[], int, int, byte).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Object[], Int32, Int32, Object)

Searches a range of the specified array for the specified object using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;IILjava/lang/Object;)I", "")]
public static int BinarySearch (Java.Lang.Object[] a, int fromIndex, int toIndex, Java.Lang.Object key);
[<Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;IILjava/lang/Object;)I", "")>]
static member BinarySearch : Java.Lang.Object[] * int * int * Java.Lang.Object -> int

Parameters

a
Object[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Object

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if an element in the array or the search element does not implement Comparable, or cannot be compared to each other.

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array for the specified object using the binary search algorithm. The range must be sorted into ascending order according to the Comparable natural ordering of its elements (as by the #sort(Object[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. (If the range contains elements that are not mutually comparable (for example, strings and integers), it cannot be sorted according to the natural ordering of its elements, hence results are undefined.) If the range contains multiple elements equal to the specified object, there is no guarantee which one will be found.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(java.lang.Object[], int, int, java.lang.Object).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Double[], Int32, Int32, Double)

Searches a range of the specified array of doubles for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([DIID)I", "")]
public static int BinarySearch (double[] a, int fromIndex, int toIndex, double key);
[<Android.Runtime.Register("binarySearch", "([DIID)I", "")>]
static member BinarySearch : double[] * int * int * double -> int

Parameters

a
Double[]

the array to be searched

fromIndex
Int32

the index of the first element (inclusive) to be searched

toIndex
Int32

the index of the last element (exclusive) to be searched

key
Double

the value to be searched for

Returns

index of the search key, if it is contained in the array within the specified range; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if startIndex > endIndex

if startIndex array.length

Remarks

Searches a range of the specified array of doubles for the specified value using the binary search algorithm. The range must be sorted (as by the #sort(double[], int, int) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.

Added in 1.6.

Java documentation for java.util.Arrays.binarySearch(double[], int, int, double).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Single[], Single)

Searches the specified array of floats for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([FF)I", "")]
public static int BinarySearch (float[] a, float key);
[<Android.Runtime.Register("binarySearch", "([FF)I", "")>]
static member BinarySearch : single[] * single -> int

Parameters

a
Single[]

the array to be searched

key
Single

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array of floats for the specified value using the binary search algorithm. The array must be sorted (as by the #sort(float[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.

Java documentation for java.util.Arrays.binarySearch(float[], float).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Int64[], Int64)

Searches the specified array of longs for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([JJ)I", "")]
public static int BinarySearch (long[] a, long key);
[<Android.Runtime.Register("binarySearch", "([JJ)I", "")>]
static member BinarySearch : int64[] * int64 -> int

Parameters

a
Int64[]

the array to be searched

key
Int64

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array of longs for the specified value using the binary search algorithm. The array must be sorted (as by the #sort(long[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

Java documentation for java.util.Arrays.binarySearch(long[], long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Int32[], Int32)

Searches the specified array of ints for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([II)I", "")]
public static int BinarySearch (int[] a, int key);
[<Android.Runtime.Register("binarySearch", "([II)I", "")>]
static member BinarySearch : int[] * int -> int

Parameters

a
Int32[]

the array to be searched

key
Int32

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array of ints for the specified value using the binary search algorithm. The array must be sorted (as by the #sort(int[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

Java documentation for java.util.Arrays.binarySearch(int[], int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Int16[], Int16)

Searches the specified array of shorts for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([SS)I", "")]
public static int BinarySearch (short[] a, short key);
[<Android.Runtime.Register("binarySearch", "([SS)I", "")>]
static member BinarySearch : int16[] * int16 -> int

Parameters

a
Int16[]

the array to be searched

key
Int16

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array of shorts for the specified value using the binary search algorithm. The array must be sorted (as by the #sort(short[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

Java documentation for java.util.Arrays.binarySearch(short[], short).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Double[], Double)

Searches the specified array of doubles for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([DD)I", "")]
public static int BinarySearch (double[] a, double key);
[<Android.Runtime.Register("binarySearch", "([DD)I", "")>]
static member BinarySearch : double[] * double -> int

Parameters

a
Double[]

the array to be searched

key
Double

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array of doubles for the specified value using the binary search algorithm. The array must be sorted (as by the #sort(double[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.

Java documentation for java.util.Arrays.binarySearch(double[], double).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Char[], Char)

Searches the specified array of chars for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([CC)I", "")]
public static int BinarySearch (char[] a, char key);
[<Android.Runtime.Register("binarySearch", "([CC)I", "")>]
static member BinarySearch : char[] * char -> int

Parameters

a
Char[]

the array to be searched

key
Char

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array of chars for the specified value using the binary search algorithm. The array must be sorted (as by the #sort(char[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

Java documentation for java.util.Arrays.binarySearch(char[], char).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Byte[], SByte)

Searches the specified array of bytes for the specified value using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([BB)I", "")]
public static int BinarySearch (byte[] a, sbyte key);
[<Android.Runtime.Register("binarySearch", "([BB)I", "")>]
static member BinarySearch : byte[] * sbyte -> int

Parameters

a
Byte[]

the array to be searched

key
SByte

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array of bytes for the specified value using the binary search algorithm. The array must be sorted (as by the #sort(byte[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

Java documentation for java.util.Arrays.binarySearch(byte[], byte).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Object[], Object)

Searches the specified array for the specified object using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;Ljava/lang/Object;)I", "")]
public static int BinarySearch (Java.Lang.Object[] a, Java.Lang.Object key);
[<Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;Ljava/lang/Object;)I", "")>]
static member BinarySearch : Java.Lang.Object[] * Java.Lang.Object -> int

Parameters

a
Object[]

the array to be searched

key
Object

the value to be searched for

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Exceptions

if an element in the array or the search element does not implement Comparable, or cannot be compared to each other.

Remarks

Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the Comparable natural ordering of its elements (as by the #sort(Object[]) method) prior to making this call. If it is not sorted, the results are undefined. (If the array contains elements that are not mutually comparable (for example, strings and integers), it cannot be sorted according to the natural ordering of its elements, hence results are undefined.) If the array contains multiple elements equal to the specified object, there is no guarantee which one will be found.

Java documentation for java.util.Arrays.binarySearch(java.lang.Object[], java.lang.Object).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

BinarySearch(Object[], Object, IComparator)

Searches the specified array for the specified object using the binary search algorithm.

[Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)I", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static int BinarySearch (Java.Lang.Object[] a, Java.Lang.Object? key, Java.Util.IComparator? c);
[<Android.Runtime.Register("binarySearch", "([Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)I", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member BinarySearch : Java.Lang.Object[] * Java.Lang.Object * Java.Util.IComparator -> int

Parameters

a
Object[]

the array to be searched

key
Object

the value to be searched for

c
IComparator

the comparator by which the array is ordered. A null value indicates that the elements' Comparable natural ordering should be used.

Returns

index of the search key, if it is contained in the array; otherwise, (-(<i>insertion point</i>) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found.

Attributes

Remarks

Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the specified comparator (as by the #sort(Object[], Comparator) sort(T[], Comparator) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements equal to the specified object, there is no guarantee which one will be found.

Java documentation for java.util.Arrays.binarySearch(T[], T, java.util.Comparator<? super T>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to