Java Arrays.binarySearch(byte[] a, byte key)
Syntax
Arrays.binarySearch(byte[] a, byte key) has the following syntax.
public static int binarySearch(byte[] a, byte key)
Example
In the following code shows how to use Arrays.binarySearch(byte[] a, byte key) method.
//from ww w.ja v a2s .c om
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
// initializing sorted byte array
byte byteArr[] = {10,20,22,35,66};
// the value to be searched
byte searchVal = 35;
int retVal = Arrays.binarySearch(byteArr,searchVal);
System.out.println("The index of element 35 is : " + retVal);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »