// assume aList2 is a sorted list of integers int low = 0; int high = aList2.size() - 1; int mid; int sKey = N ; // sKey is searchKey, the value we want to find while( low <= high ) { mid = ( low + high ) / 2; // System.out.println(low + " " + mid + " " + high) ; if( aList2.get(mid) < sKey ) low = mid + 1; else if( aList2.get(mid) > sKey ) high = mid - 1; else { if (aList2.get(mid) == sKey) return (mid) ; else return( mid * -1) ; } }