检查字符串是否包含数组中的所有字符串 [英] Check if string contains all strings from array
本文介绍了检查字符串是否包含数组中的所有字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查 String
是否包含来自 Array $ c $的所有
String
c>。
How to check if String
contains all Strings
from Array
.
我当前的代码:
String word = "abc";
String[] keywords = {"a", "d"};
for(int i = 0; i < keywords.length; i++){
if(word.contains(keywords[i])){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
推荐答案
如果将其包装到单独的方法中,代码将看起来更好:
The code would look much more nicer if you wrap it into a separate method:
public static boolean containsAllWords(String word, String ...keywords) {
for (String k : keywords)
if (!word.contains(k)) return false;
return true;
}
这篇关于检查字符串是否包含数组中的所有字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文