Java Arrays.binarySearch(byte[] a, int fromIndex, int toIndex, byte key)

Syntax

Arrays.binarySearch(byte[] a, int fromIndex, int toIndex, byte key) has the following syntax.

public static int binarySearch(byte[] a,  int fromIndex,  int toIndex,  byte key)

Example

In the following code shows how to use Arrays.binarySearch(byte[] a, int fromIndex, int toIndex, byte key) method.


//  w w w.  j av  a2  s  .  c  o  m
import java.util.Arrays;

public class Main {
 
   public static void main(String[] args) {

    // initializing sorted byte array
    byte byteArr[] = {10,20,22,35,77};

    // entering the value to be searched
    byte searchVal = 35;

    // the range of index
    int retVal = Arrays.binarySearch(byteArr,2,5,searchVal);

    System.out.println("The index of element 35 is : " + retVal);
  }
}

The code above generates the following result.