日期:2014-05-20 浏览次数:20735 次
import java.util.*; public class ArgTest { public static void main(String[] args) { Map m = new HashMap(); String[] arg = {"aaa","bbb","ccc","ddd","aaa","ccc","ccc"}; for(int i = 0;i < arg.length;i++){ System.out.println("\n" + arg[i]); int num = (int) m.get(arg[i]); m.put(arg[i],(num == 0 ? 1 : num++)); System.out.println(m); } } }
import java.util.*; public class ArgTest { public static void main(String[] args) { Map<String,Integer> m = new HashMap<String,Integer>(); String[] arg = {"aaa","bbb","ccc","ddd","aaa","ccc","ccc"}; for(int i = 0;i < arg.length;i++){ if(m.containsKey(arg[i])){ int temp = m.get(arg[i]); m.remove(arg[i]); m.put(arg[i], ++temp); } else{ m.put(arg[i],1); } } System.out.println(m); } }