在 Java 8 中,可以使用 contains() 方法对字符串进行模糊匹配判断是否包含某个子字符串。contains() 方法会返回一个布尔值,表示原字符串是否包含指定的子字符串。

下面是一个示例代码:

public class Main {
    public static void main(String[] args) {
        String str = "Hello, World!";
        String subStr = "World";
        
        boolean isContains = str.contains(subStr);
        
        System.out.println("是否包含:" + isContains);
    }
}

输出结果为:

是否包含:true

在上面的示例中,我们使用 contains() 方法判断 str 字符串是否包含 subStr 子字符串,返回结果为 true,表示 str 字符串中包含 subStr 子字符串。

java8 字符串模糊匹配是否包含

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

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