public final class BinarySearch extends Object
Modifier and Type | Method and Description |
---|---|
static int |
binarySearchFromTo(byte[] array,
byte value,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static int |
binarySearchFromTo(char[] array,
char value,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static int |
binarySearchFromTo(double[] array,
double value,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static int |
binarySearchFromTo(float[] array,
float value,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static int |
binarySearchFromTo(int[] array,
int value,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static int |
binarySearchFromTo(long[] array,
long value,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static int |
binarySearchFromTo(short[] array,
short value,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static <T extends Comparable<T>> |
binarySearchFromTo(T[] array,
T object,
int from,
int to)
Performs a binary search for the specified element in the specified
ascending sorted array.
|
static <T> int |
binarySearchFromTo(T[] array,
T object,
int from,
int to,
Comparator<? super T> comparator)
Performs a binary search for the specified element in the specified
ascending sorted array using the
Comparator to compare elements. |
public static int binarySearchFromTo(byte[] array, byte value, int from, int to)
array
- the sorted byte
array to search.value
- the byte
element to find.from
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.public static int binarySearchFromTo(char[] array, char value, int from, int to)
array
- the sorted char
array to search.value
- the char
element to find.from
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.public static int binarySearchFromTo(double[] array, double value, int from, int to)
array
- the sorted double
array to search.value
- the double
element to find.from
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.public static int binarySearchFromTo(float[] array, float value, int from, int to)
array
- the sorted float
array to search.value
- the float
element to find.from
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.public static int binarySearchFromTo(int[] array, int value, int from, int to)
array
- the sorted int
array to search.value
- the int
element to find.from
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.public static int binarySearchFromTo(long[] array, long value, int from, int to)
array
- the sorted long
array to search.value
- the long
element to find.from
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.public static <T extends Comparable<T>> int binarySearchFromTo(T[] array, T object, int from, int to)
array
- the sorted Object
array to search.object
- the Object
element to findfrom
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.public static <T> int binarySearchFromTo(T[] array, T object, int from, int to, Comparator<? super T> comparator)
Comparator
to compare elements.
Searching in an unsorted array has an undefined result. It's also undefined
which element is found if there are multiple occurrences of the same
element.array
- the sorted array to searchobject
- the element to findfrom
- the first index to sort, inclusive.to
- the last index to sort, inclusive.comparator
- the Comparator
used to compare the elements.public static int binarySearchFromTo(short[] array, short value, int from, int to)
array
- the sorted short
array to search.value
- the short
element to find.from
- the first index to sort, inclusive.to
- the last index to sort, inclusive.-index - 1
where the element would be inserted.Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.