Given two strings, my function is supposed to return true if big string is a combination of small string and false otherwise. i.e.
cat and catcatcatcat would return true cat and catdogcatcat would return false
I'm not sure why it is not working or whether my logic is right at all.
public static boolean isCat(String s, String y) {
int yl= y.length();
int counter= 0;
for (int i= 0; i < s.length(); i++ ) {
char[] ychar= y.toCharArray();
char[] subchar= s.substring(counter, counter + yl).toCharArray();
if (Arrays.equals(ychar, subchar) == true) {
counter+= yl;
return true;
}
}
return true;
}