代码如下:
String urlString="http://localhost:8080/adm/subComInfo/propConfigList";
if (urlString.contains("list") || urlString.contains("/propConfigList") ) {
manageLog.setOperateType("查询");
要判断urlString,是否包含,list 等多个子字符串,用上面这种写法是可以实现,
问题,如果要判断的子字符串有很多个,就不太美观,请问,是否有一个集合工具方法,能够让我,判断一个长字符串中,如果,包含多个子字符串中的一个,如果包含就返回true?
高洛峰2017-04-18 09:53:56
function boolean s1(String longString, List<String> StrList){
for(String str : StrList){
if(longString.contains(str)){
return true;
}
}
return false;
}
天蓬老师2017-04-18 09:53:56
Is your requirement to determine whether an element in a string array is a substring of another string? If so, you can write a method:
public class Main {
public static void main(String[] args) {
String[] strings = {"www", "http"};
String sourceString = "https://www.baidu.com/";
boolean contain = contains(sourceString, strings);
System.out.println(contain);//是否包含
}
private static boolean contains(String sourceString, String[] strings) {
boolean contain = false;
for (String s : strings) {
if (sourceString.contains(s)) {
contain = true;
}
}
return contain;
}
}