![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Collections og streams - slide 16 : 35 |
import java.util.*; public class Freq { private static final Integer ONE = new Integer(1); private static Integer incr(Integer i){ return new Integer(i.intValue() + 1); } public static void main(String args[]) { Map m = new HashMap(); // 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 : incr(freq)); } System.out.println(m.size()+" distinct words detected:"); System.out.println(m); } } |
|