java代码(list是LogStat类型的集合):
Map<String, List> mapUK = new HashMap<String, List>();
try {
for(LogStat u : list) {
if(mapUK.containsKey(u.getKeshiName())) {
mapUK.get(u.getKeshiName()).add(u);
} else {
List userK = new ArrayList();
userk.add(u);
mapUK.put(u.getKeshiName, userK);
}
}
} catch(Exception e) {
e.printStackTrace();
}
Set set = mapUK.enterSet();
Iterator itr = set.iterator();
while(itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
String key = itr.next();//mapUK.get(key);
System.out.println(“科室:”+entry.getKey());
for(LogStat u : mapUK.get(entry.getKey())) {//mapUK.get(key)和mapUK.get(entry.getKey())等同
System.out.println(“用户名:”+u.getUserName());
}
}