日期:2014-05-20 浏览次数:20856 次
String [] a ={a,b,c,a,c,b,d,e}; String [] b ={1,2,3,1,3,2,4,5}; Map<String, Integer> group = new HashMap<String, Integer>(); StringBuilder buf = new StringBuilder(); for (int i=0; i<a.length; i++) { buf.delete(0, key.length()); buf.append(a[i]).append(",").append(b[i]); String key = buf.toString(); if (group.containsKey(key)) { group.put(key, grout.get(key)+1); } else { group.put(key, 1); } } System.out.printf("has %d group\n", map.size()); for (Map.Entry<String, Integer> e : map.entrySet()) { System.out.printf("group[%s], count[%d]\n", e.getKey(), e.getValue()); }