Counting distinct words with Threads

前端 未结 1 998
无人及你
无人及你 2021-01-27 09:06

The objective is to count distinct words from a file.

UPDATE: Previous Code was successfully finished. Now I have to do the same but using threads (Oh

相关标签:
1条回答
  • 2021-01-27 09:30

    Why don't you sinply try something like:

    public int countWords(File file) {
        Scanner sc = new Scanner(file);
        Set<String> allWords = new HashSet<String>();
        while(sc.hasNext()) {
            allWords.add(sc.next());
        }
        return allWords.size();
    }
    
    0 讨论(0)
提交回复
热议问题