I would like to check whether a string contains a sub list.
For example, str1 = "qwertyuiop" and str2 = "tyu" returns true.
I have written an iterative method.
public static boolean checkString(String str1, String str2) {
for (int i=0; i<str2.length(); i++) {
int j = 0;
for (; j<str1.length()&& str1.charAt(j)!=str2.charAt(i); j++) {
}
if (j== str1.length())
return false;
}
return true;
}
I am trying changing it to recursive method but not sure how as there are two nested for loops.
Thank you in advance.
recursionwill work when there's more than one loop.