這是拼寫檢查器中的一種方法。正如標題所解釋的,當且僅當所有添加到數組列表中的單詞都在父數組單詞中找到時,纔會返回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中的所有內容都已知。 –