目前有两个 list:(数据类型是 List<Map<String,String> Java 程序 ) list1: 数据少,携带 list2 主键 businessId 可以关联到 list2 list2:数据大,
(求交集)如果 list2 中 businessId 在 list1 存在的话,将该条 map,拼接到 list1 中, 最后返回拼接好的 list eg:
list1: {
[
id: 1
businessId: 101,
...
],
[
id:2,
businessId: 102,
...
]
}
list2: {
[
businessId: 101,
name: xiaoming,
...
],
[
businessId: 102,
name: daqiang,
...
],
[
businessId: 103,
name: xiaohong,
...
],
....
}
返回:
list: {
[
id: 1
businessId: 101,
name: xiaohong,
...
],
[
id: 2,
businessId: 102,
name: daqiang,
...
]
}
双层遍历的话,因为 list2 会慢慢变大,时间复杂度会越来越高,请问怎么处理能快速得到两个 list 的交集
1
coffeSlider 2019-03-18 17:10:06 +08:00
把 list2 改为 map {
businessId: 101, list:{ businessId: 101, name: xiaoming, ... } } |
2
coffeSlider 2019-03-18 17:11:19 +08:00
结构如下 map {
101:{ businessId: 101, name: xiaoming, ... }, 102:{ businessId: 102, name: xiaowang, ... } } |