is substring of string
public int isSubstring(String one, String two){
if (one == null || two == null || two.length() > one.length()) return -1;
if (two.length() == 0) return 0;
//check all possible positions of first char string two
for (int i = 0; i <= (one.length - two.length); i++){
int j = 0;
while (j < two.length() && one.charAt(i + j) == two.charAt(j){
j++;
}
if (j = two.length()) return i;
}
return -1;
}
Last updated