-1
我想要做的是從包含500,000英文單詞的文本文件中讀取並將其存儲到HashSet以達到性能目的。然後我想返回一個包含合格元素的HashSet,例如5個字母的單詞,6個字母的單詞等。如何遍歷HashSet並返回帶有限定元素的集合?
這是我的代碼,至今我不知道該怎麼做。 我很感謝你的解決方案!
private static HashSet<String> readPuzzleFile(int wordLength) {
HashSet<String> unProcessedPuzzle = new HashSet<String>();
try (Scanner file = new Scanner(new File(PATHTOPUZZLE))) {
while (file.hasNextLine()) {
unProcessedPuzzle.add(file.nextLine());
}
} catch (FileNotFoundException e) {
System.out.println("No Puzzle File Found!");
return null;
}
HashSet<String> puzzle = new HashSet<String>();
Iterator iterator = unProcessedPuzzle.iterator();
for (String word : unProcessedPuzzle){
puzzle.addAll(word);
}
}
而且你有什麼問題或你的問題? – IQV
@IQV如何做到這一點,抱歉忘了第一次把它放在問題中。 –
如何做什麼? – shmosel