Check out example codes for "java indexof nth occurrence". It will help you in understanding the concepts better.

Code Example 1

public static int ordinalIndexOf(String str, String substr, int n) {
    int pos = str.indexOf(substr);
    while (--n > 0 && pos != -1)
        pos = str.indexOf(substr, pos + 1);
    return pos;
}

Learn ReactJs, React Native from akashmittal.com