-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