Java
Mapmap = new HashMap ();// MYObject:为自定义类,取id作为key,然后,进行数目统计for (MyObject temp : list) { Integer count = map.get(temp.getId()); map.put(temp.getId(), (count == null) ? 1 : count + 1);}// 打印统计for (Map.Entry entry : map.entrySet()) { System.out.println("Key : " + entry.getKey() + " Value : " + entry.getValue());}