private int[] startWith(String gram)
    {
        int[] range = {-1, -1};
        int[] temp = null;
        int str = 0;
        int end = this.trigram.length - 1;
        while (str <= end) {
            int mid = (str + end) / 2;
            String[] grams = getGrams(this.trigram[mid]);
            if (grams[0].compareTo(gram) == 0) {
                // Store str and end when first access, to avoid duplicate search steps.
                if (temp == null)
                    temp = new int[]{str, end};
                // Find the lower bound of the gram range.
                if (range[0] == -1) {
                    if (mid == 0 || getGrams(this.trigram[mid - 1])[0].compareTo(gram) < 0) {
                        range[0] = mid;
                        str = temp[0];
                        end = temp[1];
                    } else {
                        end = mid - 1;
                    }
                // Find the upper bound of the gram range.
                } else {
                    if (mid == this.trigram.length - 1 || getGrams(this.trigram[mid + 1])[0].compareTo(gram) > 0) {
                        range[1] = mid;
                        break;
                    } else {
                        str = mid + 1;
                    }
                }
            } else if (grams[0].compareTo(gram) < 0) {
                str = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        return range;
    }