Java Arrays binary search an array
import java.util.Arrays; public class Main { public static void main(String[] args) { byte bArray[] = { 1, 2, 4, 5 ,6, 8,9}; Arrays.sort(bArray);//from w w w.ja 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 = 7; intResult = Arrays.binarySearch(bArray, searchValue); System.out.println("Result of binary search of 3 is : " + intResult); } }