public static int binarySearch(Object array[], Object key)
public static int binarySearch(Object array[], Object key, Comparator c)
import java.util.Arrays;
public class MainClass {
public static void main(String[] a) {
String str[] = { "B", "H", "L", "M", "I", "N", "R" };
// Ensure list sorted
Arrays.sort(str);
for (String s : str) {
System.out.println(s);
}
// Search for element in list
int index = Arrays.binarySearch(str, "M");
System.out.println("Found M @ " + index);
}
}
B
H
I
L
M
N
R
Found M @ 4