Here you can find the source of binarySearch(int[] source, int key)
public static int binarySearch(int[] source, int key)
//package com.java2s; //License from project: LGPL public class Main { public static int binarySearch(int[] source, int key) { int low = 0, high = source.length - 1, mid; while (low <= high) { mid = (low + high) >>> 1; if (key == source[mid]) { return mid; } else if (key < source[mid]) { high = mid - 1;/*from www . j a v a 2 s .c o m*/ } else { low = mid + 1; } } return -1; } }