How to populate a List within a Map
Hello folks, hope you can help me with a little task. I want to make a Map that populates with <String> List<Fish>, but am having issues. Here's the code:
Code:
import java.util.*;
public class FishFarm
{
private HashMap findFish;
public FishFarm()
{
Map<String, List<Fish>> findFish = new HashMap<String, List<Fish>>();
}
public void fish()
{
HashMap findFish = new HashMap<String, List<Fish>>();
}
public void addFish()
{
List<Fish> temp;
temp = new ArrayList<Fish>();
temp.add(new Fish("Shark","Carnavour", "Salt Water",20));
this.findFish.put("Shark", temp);
this.findFish.get("Shark").add(new Fish("Shark","Carnavour", "Salt Water",20));
}
}
Problem I get is on line Code:
this.findFish.get("Shark").add(new Fish("Shark","Carnavour", "Salt Water",20));
...where the compiler says cannot find symbol - method add(Fish). So I can't get the List in the map to populate with the new object of type Fish. Any ideas?
many thanks in advance