【发布时间】:2022-01-08 20:45:28
【问题描述】:
当我尝试将案件编号添加到每个国家/地区的每个日期时,我遇到了困难。在我的尝试中,它只会添加每个国家/地区每个日期的整个记录列表
下面是List<List<String>> covidConfirmedList的输出
[Province/State, Country/Region, Lat, Long, 1/22/20, 1/23/20, 1/24/20, 1/25/20, 1/26/20, 1/27/20]
[, Afghanistan, 33.93911, 67.709953, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]
[, Angola, -11.2027, 17.8739, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]
[, Angeria, -12.3047, 17.8739, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]
[, Andora, -13.2087, 17.8739, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]
我打算存储在 Map
预期输出
Afghanistan --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[3], 2020-01-25=[0], 2020-01-26=[0]}
Angola --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[0], 2020-01-25=[0], 2020-01-26=[0]}
Angeria --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[0], 2020-01-25=[0], 2020-01-26=[0]}
Andora --> {2020-01-22=[0], 2020-01-23=[0], 2020-01-24=[0], 2020-01-25=[0], 2020-01-26=[0]}
我的尝试
Map<String, Map<LocalDate, List<Integer>>> dataMap = new LinkedHashMap<>();
Map<LocalDate,List<Integer>> innerMap = new LinkedHashMap<>();
IntStream //functional for loop to add the date as keys into the map
.range(0,covidListWithoutCountryDetails.get(0).size())
.forEach(i->
innerMap
.put(keys.get(i),new ArrayList<>()
)
);
IntStream //functional for loop to add the country keys into map
.range(0,mapKeys.size())
.forEach(i->dataMap
.put(mapKeys.get(i), innerMap));
【问题讨论】:
标签: java linkedhashmap