Here you can find the source of binarySearch(String[] array, String sought)
public static boolean binarySearch(String[] array, String sought)
//package com.java2s; public class Main { public static boolean // true if 'sought' is in 'array' binarySearch(String[] array, // must be sorted in ascending order String sought) { int first = 0; int len = array.length; int half, middle; int compare; while (len > 0) { half = len / 2;//ww w . j a v a 2 s .co m middle = first + half; compare = array[middle].compareTo(sought); if (compare < 0) { first = middle + 1; len -= half + 1; } else if (compare > 0) { len = half; } else { return true; } } return false; } }