编写函数boolean containsAny(String str, String searchChars) 判断str字符串中是否包含searchChars字符串?
匿名 | 浏览 78171 次 2012-04-28 16:30
2015-09-28 21:44最佳答案
java判断字符串中包含特定字符串方法:
使用正则表达式进行判断。
源代码:
public class Test {
public static void main(String[] args) {
String str="Hello World" //待判断的字符串
String reg=".*ll.*" //判断字符串中是否含有特定字符串ll
System.out.println(str.matches(reg))
}
}
1、在程序中需要引入hutool的jar包。
2、创建一个Sting类型的字符串数字。
3、接着创建多个字符串指定查询。
4、booleancontains=StrUtil.containsAny(phone,s1);//字符串中是否包含任意一个。
5、运行程序查看得到的结果。