Java Binary Search binarySearchStringArray(String[] array, String item, int first, int last)

Here you can find the source of binarySearchStringArray(String[] array, String item, int first, int last)

Description

binary Search String Array

License

Open Source License

Declaration

public static int binarySearchStringArray(String[] array, String item, int first, int last) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int binarySearchStringArray(String[] array, String item, int first, int last) {
        if (last < first) {
            return -1;
        }/*from  w w w .j  a  va 2  s. c o  m*/
        int mid = (first + last) / 2;
        if (array[mid].equals(item)) {
            return mid;
        }
        if (item.compareTo(array[mid]) < 0) {
            return binarySearchStringArray(array, item, first, mid - 1);
        } else {
            return binarySearchStringArray(array, item, mid + 1, last);
        }
    }
}

Related

  1. binarySearch0(float[] a, int fromIndex, int toIndex, float key)
  2. binarySearchCeil(double[] a, double key)
  3. binarySearchIndex(double[] values, double toFind)
  4. binarySearchLower(int[] theSearchBase, int theLowerBound, int theUpperBound, int theKey)
  5. binarySearchReversed(int[] a, int fromIndex, int toIndex, int key)