レストランの ID である整数値としてキーを格納する HashMap を作成したいと考えています。値はレストラン オブジェクトのリストである必要があります。しかし、私の IDE は、レストラン オブジェクトをリストに追加するときの方法に満足していません。これが私のコードです:
public List getTopPerformers(List<RestaurantInfo> restaurants){
HashMap <Integer, List<RestaurantInfo>> map = new HashMap<Integer,
List< RestaurantInfo>>();
// Key is restaurant ID. Value is the Object of Class RestaurantInfo
List<RestaurantInfo> ll;
for(RestaurantInfo restaurant: restaurants){
map.put(restaurant.cityId, ll.add(restaurant));
}
}
私のレストラン クラスには、cityId、orderCount、restaurantId などのプロパティがあります。
行は次のmap.put(restaurant.cityId, ll.add(restaurant));
ようにエラーを出し、明らかにコンパイルされません。
no suitable method found for put(int,boolean)
method HashMap.put(Integer,List<RestaurantInfo>) is not applicable