这是拼写检查器中的一种方法。正如标题所解释的,当且仅当所有添加到数组列表中的单词都在父数组单词中找到时,才会返回true。否则,它应该返回一个错误的值。我一直在争取与此几个小时,这是我目前的情况......检查另一个阵列列表中的阵列列表
/**
* This method returns true if (and only if) all words in the
* given wordList are found in the dictionary.
*/
public boolean allKnown(ArrayList<String> wordList)
{
boolean result = true;
for(int index = 0; index < wordList.size(); index++)
{
if(words.contains(!wordList.contains(index)))
{
result = false;
}
result = true;
}
return result;
}
我真正需要的是转出yes或no的方式,但我迷路了。 请尝试使用给出的代码,因为这是一个练习来教授代码。 谢谢!
复制正在测试的ArrayList,然后copy.removeAll(已知)并测试复制的大小,如果0中的所有内容都已知。 –