package com.fgh.collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
/**
* 在命令行输入参数 判断每个参数输入的次数
* @author fgh
*
*/
public class InputTimes {
public static void main(String[] args) {
HashMap map = new HashMap();
for (int i = 0; i < args.length; i++) {
if (map.get(args[i]) == null) {
map.put(args[i], new Integer(1));
} else {
Integer in = (Integer) map.get(args[i]);
in = new Integer(in.intValue() + 1);
map.put(args[i], in);
}
}
Set set = map.keySet();
for (Iterator iter = set.iterator(); iter.hasNext();) {
String key = (String) iter.next();
Integer value = (Integer) map.get(key);
System.out.println(key + " : " + value +"次");
}
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
/**
* 在命令行输入参数 判断每个参数输入的次数
* @author fgh
*
*/
public class InputTimes {
public static void main(String[] args) {
HashMap map = new HashMap();
for (int i = 0; i < args.length; i++) {
if (map.get(args[i]) == null) {
map.put(args[i], new Integer(1));
} else {
Integer in = (Integer) map.get(args[i]);
in = new Integer(in.intValue() + 1);
map.put(args[i], in);
}
}
Set set = map.keySet();
for (Iterator iter = set.iterator(); iter.hasNext();) {
String key = (String) iter.next();
Integer value = (Integer) map.get(key);
System.out.println(key + " : " + value +"次");
}
}
}
输出结果:
hello : 1次
t : 1次
test : 2次
world : 1次