-1

I faced the difficulties when I try to add the cases number into each date of each country. In my attempt, it will only add the whole list of the record in each date of each country

Below is the output of the 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]

I intend to store in the Map<String, Map<LocalDate, List>>. In each date of each country, it should have only store one single record.

Expected Output

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]} 

My attempt

 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));
mike kong
  • 47
  • 7

1 Answers1

-1

I see you are using LocalDate as a key - wouldn't it duplicate keys?

bkomo
  • 65
  • 1
  • 9