日期:2014-05-20 浏览次数:20822 次
package com.ibm.lan.test; import java.util.HashMap; import java.util.Map; public class CountTest { public static void main(String[] args) { String s = "张三,李四,张三,小王,张三"; Map<String, Integer> map = new HashMap<String, Integer>(); String[] ss = s.split(","); for (String temp : ss) { if (map.containsKey(temp)) { map.put(temp, map.get(temp) + 1); } else { map.put(temp, 1); } } System.out.println(map); } }