import java.util.HashMap;
import java.util.Map;
public class FindTheWordFrequency {
public static void main(String[] args) {
// TODO Auto-generated method stub
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);
}
}
Console:
0 distinct words:
{}