import java.util.*;
public class Freq
{ private static final Integer ONE = new Integer(1);
public static void main(String args[])
{ Map m = new TreeMap();
// Initialize frequency table from command line for (int i=0; i < 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); } }
/** 실행:java Freq if it is to be it is up to me to delegate 결과: 8 distinct words detected: {be=1, delegate=1, if=1, is=2, it=2, me=1, to=3, up=1} */
|