list集合分组:根据对象某一属性分组

private Map<String, List<CreditContractSignSerial>> listGroup2MapTwo(List<CreditContractSignSerial> list) {
Map<String, List<CreditContractSignSerial>> userSignSerialMap = Maps.newConcurrentMap();
if (CollectionUtils.isNotEmpty(list)) {
// 分组
for (CreditContractSignSerial vo : list) {
String transDate = new SimpleDateFormat("yyyyMMdd").format(vo.getCreateTime());

List<CreditContractSignSerial> tempList = userSignSerialMap.get(transDate);
/*如果取不到数据,那么直接new一个空的ArrayList**/
if (tempList == null) {
tempList = Lists.newArrayList();
tempList.add(vo);
userSignSerialMap.put(transDate, tempList);
}
else {
/*某个vo之前已经存放过了,则直接追加数据到原来的List里**/
tempList.add(vo);
}
}
}
return userSignSerialMap;
}

posted on 2019-02-25 08:49  runmove  阅读(3446)  评论(0编辑  收藏  举报