我试图查看字符串的 ArrayList 是否包含位于另一个字符串中的单词,但我做错了。这是我的代码: 这是我的 ArrayList 的示例
titles = {“钠”,“锂”,“诱惑红 AC”};
String ocrRes = "I want some sugar , and some coffee with Allura Red AC , Ponceau 4R ";
for (int i = 0; i < titles.size() ; i++)
{
if (ocrRes.contains(titles.get(i)) )
{
ocrResult.setText(titles.get(i));
}
}
任何帮助将不胜感激。提前谢谢你。
最佳答案
以下是如何在字符串数组中查找特定单词的概述:
String[] array;
//will return the index of the array where word found.
int checkWord(String searchWord)
{
for(int i = 0; i < array.length; i++)
{
if (searchWord.equals(array[i]))
return i;
}
}
你可以实现类似这样的东西来在你的数组中找到一个词,希望这对你有帮助:)
关于java - 如何检查字符串列表是否包含特定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43033595/