Purpose: find the number of all words in a file. file contains more than 1000 words
My approach: use HashMap<String,Integer>()to store and count the number of times each word appears in a file.
Question: Would HashMap()it be better or better to use a binary tree to provide a faster search, since the file has a large number of words?
Or is there a better way to do this?
HashMap will lead to a large amount of memory overhead, which is undesirable.
source
share