I am trying to find the first occurrence of a letter in a string. For example, p in apple should return 1. Here is what I have:
// Returns the index of the of the character ch
public static int indexOf(char ch, String str) {
if (str == null || str.equals("")) {
return -1;
} else if(ch == str.charAt(0)) {
return 1+ indexOf(ch, str.substring(1));
}
return indexOf(ch, str.substring(1));
}
It just doesn't seem to be returning the correct value.
String.indexOf(int ch)?