/**
* 通过遍历两个List中按名称关联匹配
* @param oneList
* @param twoList
* @param govLevel
*/
public static List<实体> compareListHitData(List<实体> oneList, List<实体> twoList, int govLevel) {
switch (govLevel) {
case 2:
List<实体> cityList = oneList.stream().map(user -> twoList.stream()
.filter(city -> Objects.equals(one字段, two字段))
.findFirst().map(i -> {
user.setCityCode((String) i.get("value"));// 需合并字段
return user;
}).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toList());
return cityList;
case 3:
List<ExcelUserEntity> countyList = oneList.stream().map(user -> twoList.stream()
.filter(county -> Objects.equals(one字段, two字段) &&
Objects.equals(one字段, two字段)
)
.findFirst().map(i -> {
user.setCountyCode((String) i.get("value"));// 需合并字段
return user;
}).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toList());
return countyList;
case 4:
List<ExcelUserEntity> townsList = oneList.stream().map(user -> twoList.stream()
.filter(town -> Objects.equals(one字段, two字段) && Objects.equals(one字段, two字段)
)
.findFirst().map(i -> {
user.setTownsCode((String) i.get("value"));// 需合并字段
return user;
}).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toList());
return townsList;
default:
return oneList;
}
}
java 遍历两个List按名称关联匹配合并
于 2022-12-02 08:58:43 首次发布