List<Member> memberList = this.searchMemberByCabin_eiden(voyage_code);
//自行分组,分组算法
Map<Integer, List<Member>> CabinIdMap = new HashMap<>();
for (Member m : memberList) {
List<Member> tempList = CabinIdMap.get(m.getCabin_lib_id());
/*如果取不到数据,那么直接new一个空的ArrayList**/
if (tempList == null) {
tempList = new ArrayList<>();
tempList.add(m);
CabinIdMap.put(m.getCabin_lib_id(), tempList);
}else {
/*某个member之前已经存放过了,则直接追加数据到原来的List里**/
tempList.add(m);
}
}
for (Cabin c : cabins) {
c.setMembers(CabinIdMap.get(c.getCabin_lib_id()));
}
jdk1.8
Map<String, List<String>> dbSourceMap2 = new HashMap<>(16);
for (OrderTenant orderTenant : orderTenantList) {
String tenantName = orderTenant.getTenantName();
//若key对应的value为空,会将第二个参数的返回值存入并返回
List<String> waybillNoList = dbSourceMap2.computeIfAbsent(tenantName, k -> new ArrayList<>());
waybillNoList.add(tenantName);
}