Slide 16
Slide 16 text
public Map convert(List customers) {
Map productCountMap = new HashMap<>();
for (int i = 0; i < customers.size(); i++) {
Customer customer = customers.get(i);
List ids = customer.getHistory();
for (int j = 0; j < ids.size(); j++) {
int pId = ids.get(j);
Long productCount = productCountMap.get(pId);
if (productCount == null) {
productCountMap.put(pId, 1L);
} else {
productCount++;
productCountMap.put(pId, productCount);
}
}
}
return productCountMap;
}
いにしえの書き方