Collections.BinarySearch Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
BinarySearch(IList, Object) |
Searches the specified list for the specified object using the binary search algorithm. |
BinarySearch(IList, Object, IComparator) |
Searches the specified list for the specified object using the binary search algorithm. |
BinarySearch(IList, Object)
Searches the specified list for the specified object using the binary search algorithm.
[Android.Runtime.Register("binarySearch", "(Ljava/util/List;Ljava/lang/Object;)I", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static int BinarySearch (System.Collections.IList list, Java.Lang.Object key);
[<Android.Runtime.Register("binarySearch", "(Ljava/util/List;Ljava/lang/Object;)I", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member BinarySearch : System.Collections.IList * Java.Lang.Object -> int
Parameters
- list
- IList
the list to be searched.
- key
- Object
the key to be searched for.
Returns
the index of the search key, if it is contained in the list;
otherwise, (-(<i>insertion point</i>) - 1)
. The
insertion point is defined as the point at which the
key would be inserted into the list: the index of the first
element greater than the key, or list.size()
if all
elements in the list are less than the specified key. Note
that this guarantees that the return value will be >= 0 if
and only if the key is found.
- Attributes
Remarks
Searches the specified list for the specified object using the binary search algorithm. The list must be sorted into ascending order according to the Comparable natural ordering of its elements (as by the #sort(List)
method) prior to making this call. If it is not sorted, the results are undefined. If the list contains multiple elements equal to the specified object, there is no guarantee which one will be found.
This method runs in log(n) time for a "random access" list (which provides near-constant-time positional access). If the specified list does not implement the RandomAccess
interface and is large, this method will do an iterator-based binary search that performs O(n) link traversals and O(log n) element comparisons.
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(IList, Object, IComparator)
Searches the specified list for the specified object using the binary search algorithm.
[Android.Runtime.Register("binarySearch", "(Ljava/util/List;Ljava/lang/Object;Ljava/util/Comparator;)I", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static int BinarySearch (System.Collections.IList list, Java.Lang.Object? key, Java.Util.IComparator? c);
[<Android.Runtime.Register("binarySearch", "(Ljava/util/List;Ljava/lang/Object;Ljava/util/Comparator;)I", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member BinarySearch : System.Collections.IList * Java.Lang.Object * Java.Util.IComparator -> int
Parameters
- list
- IList
the list to be searched.
- key
- Object
the key to be searched for.
the comparator by which the list is ordered.
A null
value indicates that the elements'
Comparable natural ordering should be used.
Returns
the index of the search key, if it is contained in the list;
otherwise, (-(<i>insertion point</i>) - 1)
. The
insertion point is defined as the point at which the
key would be inserted into the list: the index of the first
element greater than the key, or list.size()
if all
elements in the list are less than the specified key. Note
that this guarantees that the return value will be >= 0 if
and only if the key is found.
- Attributes
Remarks
Searches the specified list for the specified object using the binary search algorithm. The list must be sorted into ascending order according to the specified comparator (as by the #sort(List, Comparator) sort(List, Comparator)
method), prior to making this call. If it is not sorted, the results are undefined. If the list contains multiple elements equal to the specified object, there is no guarantee which one will be found.
This method runs in log(n) time for a "random access" list (which provides near-constant-time positional access). If the specified list does not implement the RandomAccess
interface and is large, this method will do an iterator-based binary search that performs O(n) link traversals and O(log n) element comparisons.
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.