public abstract class Main {
public static boolean getResult(String targetStr, String str) {
if (targetStr.contains(str)) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
String targetStr = "I love china,my motherland!";
String str = "china";
System.out.println(getResult(targetStr, str));
}
}
主要是使用一个方法contains(),可以判断字符串中是否包含指定的子串。