Performing Binary Search on byte Array - Java Language Basics

Java examples for Language Basics:byte

Description

Performing Binary Search on byte Array

Demo Code

 
import java.util.Arrays;
 
public class Main {
  public static void main(String[] args) {
    byte bArray[] = {1,2,4,5};

    Arrays.sort(bArray);// w  w  w .  j  a v a  2 s .co  m
   
    byte searchValue = 2;
   
    int intResult = Arrays.binarySearch(bArray,searchValue);
    System.out.println("Result of binary search of 2 is : " + intResult);
   
    searchValue = 3;
    intResult = Arrays.binarySearch(bArray,searchValue);
    System.out.println("Result of binary search of 3 is : " + intResult);
 
  }
}

Result


Related Tutorials