gpt4 book ai didi

android - 一一检查ArrayList of Strings是否包含50个不同的String

转载 作者:行者123 更新时间:2023-11-29 14:48:12 28 4
gpt4 key购买 nike

如何检查字符串的ArrayList是否包含字符串数组中的50个不同字符串中的每一个,并对ArrayList中的每个相同字符串做某事?

最佳答案

您可以使用此函数来检查数组中的所有字符串是否也在 ArrayList 中。如果您想添加额外的逻辑,例如每次找到匹配项时执行 doSomething(),您应该能够轻松调整代码。

ArrayList myList; // let's assume its initialized and filled with Strings
String[] strArray; // let's assume its initialized and filled with Strings

//this function returns true if all Strings in the array are also in your arraylist

public boolean containsAll(myList, strArray){
//iterate your String array
for(int i = 0; i < strArray.length; i++){
if(!myList.contains(strArray[i])){
//String is not in arraylist, no need to check the rest of the Strings
return false;
}
}
return true;
}

关于android - 一一检查ArrayList of Strings是否包含50个不同的String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27959777/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com