按照List中Object的某個屬性進行分組
阿新 • • 發佈:2019-02-10
/**
*
* 按照List中Object的某個屬性contNo,進行分組
*
* @author fuqin
* create on 2009-12-11
*
* @param list
* @return
*/
public static Map getListByKey(List list) {
Map map = new HashMap();
for (int i = 0; list != null && i < list.size(); i++) {
LifePaymentInfo obj = (LifePaymentInfo) list.get(i);
String key = obj.getContNo();
if (map.containsKey(key)) {
List lists = (List) map.get(key);
lists.add(obj);
} else {
List lists = new ArrayList();
lists.add(obj);
map.put(key, lists);
}
}
return map;
}