基本操作 (put, get, remove, containsKey, containsValue, s , a和isEmpty) 的功能与它们在Hashtable中的对等物非常相似。下面的简单程序针对参数列表中的词汇生成一个频率表。频率表将每个词和它在参数列表中所出现的次数相映射。
import java.util.*; public class Freq { PRivate static final Integer ONE = new Integer(1); public static void main(String args[]) { Map m = new HashMap(); // Initialize frequency table from command line for (int i=0; i$#@60; args.length; i++) { Integer freq = (Integer) m.get(args[i]); m.put(args[i], (freq==null ? ONE : new Integer(freq.intValue() + 1))); }
System.out.println(m.size()+" distinct Words detected:"); System.out.println(m); } } QQread.com 推出各大专业服务器评测 linux服务器的安全性能