JAVA算法:字符串A中是否包含字符串B
public static void main(String[] args) {
test5("aabbccdd","dd");
}
//if (baseChar[i] == searchChar[0] && i + searchChar.length <= baseChar.length)
private static void test5(String str, String search){
char[] strChar = str.toCharArray();
char[] searchChar = search.toCharArray();
boolean exist = false;
for (int i = 0; i < strChar.length; i++) {
int j = 1;
if (strChar[i] == searchChar[0]) {
for (; j < searchChar.length; j++) {
if (searchChar[j] != strChar[i + j]) {
break;
}
}
}
if(j == searchChar.length){
exist = true;
break;
}
}
System.out.println(exist);
}