可以使用字符串的contains()方法来判断字符串中是否包含某个字符串。例如:

String str = "Hello, World!";
String subStr = "Hello";

if (str.contains(subStr)) {
    System.out.println("字符串中包含子字符串");
} else {
    System.out.println("字符串中不包含子字符串");
}

输出结果为:"字符串中包含子字符串"。

java判断字符串中是否包含某个字符串

原文地址: https://www.cveoy.top/t/topic/itFz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录