提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Java用Map查找词频
import java.util.*; public class Freq { public static void main(String[] args) {/** N o w J a v a . c o m 提供 **/ Map<String, Integer> m = new HashMap<String, Integer>(); // Initialize frequency table from command line for (String a : args) { Integer freq = m.get(a); m.put(a, (freq == null) ? 1 : freq + 1); } System.out.println(m.size() + " distinct words:"); System.out.println(m); } }