Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我设法解析给定输入文本文件的全部内容并将每个单词存储在哈希集中。但是现在我需要在这个输入文件中找到每个单词的频率,关于我该怎么做的任何建议?:)
使用 aHashMap而不是 aHashSet和此类作为值:
HashMap
HashSet
class Counter { public int frequency; }
addWord()然后看起来像这样:
addWord()
public void addWord (String word) { Counter c = map.get (word); if (c == null) { c = new Counter (); map.put(word, c); } c.frequency ++; }