public static int nthOccurrenceOf(final String s, final char needle, int n) {
    checkNotNull(s);
    checkArgument(n > 0);
    for (int i = 0; i < s.length(); ++i) {
      if (needle == s.charAt(i)) {
        --n;
        if (n == 0) {
          return i;
        }
      }
    }
    return -1;
  }
public static int nthOccurrenceOf ( final String s , final char needle , int n ) { checkNotNull ( s ) ; checkArgument ( n > 0 ) ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { if ( needle == s . charAt ( i ) ) { -- n ; if ( n == 0 ) { return i ; } } } return - 1 ; }
* Returns the index of the {@code n}-th occurence of {@code needle} in {@code s}. If {@code needle}
does not appear in {@code s}, returns -1.

@param s      The string to search. Cannot be null.
@param needle The character to search for.
@param n      Return the {@code n}-th occurence