Here you can find the source of binarySearch(T[] a, T x)
public static <T extends Comparable<? super T>> int binarySearch(T[] a, T x)
//package com.java2s; //License from project: Open Source License public class Main { public static <T extends Comparable<? super T>> int binarySearch(T[] a, T x) { int low = 0, high = a.length - 1; while (low <= high) { int mid = (low + high) / 2; if (a[mid].compareTo(x) < 0) low = mid + 1;//from w w w .j a v a2 s.co m else if (a[mid].compareTo(x) > 0) high = mid - 1; else return mid; } return -1; } }