Java - Write code to get the first Index Of a Char

Requirements

Write code to get the first Index Of a Char

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String sqlString = "book2s.com";
        String string = "b";
        int startindex = 4;
        System.out.println(firstIndexOfChar(sqlString, string, startindex));
    }/*from w w w  .  j  ava 2s.c o m*/

    public static int firstIndexOfChar(String sqlString, String string,
            int startindex) {
        int matchAt = -1;
        for (int i = 0; i < string.length(); i++) {
            int curMatch = sqlString.indexOf(string.charAt(i), startindex);
            if (curMatch >= 0) {
                if (matchAt == -1) { // first time we find match!
                    matchAt = curMatch;
                } else {
                    matchAt = Math.min(matchAt, curMatch);
                }
            }
        }
        return matchAt;
    }
}