我正在尝试访问存储在地图中包含的列表中的一些元素。地图中的键是双键。我试图访问的列表包含双精度和映射。下面的代码是我尝试将双精度存储在列表中,以及访问列表中包含的地图。下面的代码中有3个错误,我不知道如何解决。任何帮助都会非常感谢。
private Map<Double,List<Object>> prediction = new HashMap<Double,List<Object>>();
// previous is a double that the user inputs
if(prediction.containsKey(previous)){
List<Object> l1 = new ArrayList<>();
l1.add(0,(double)l1.get(0)+1.0); // add double 1 at index 0
Map<Double,Double> m2 = new HashMap<Double,Double>();
l1.add(m2); // add map to list at index 1
prediction.put(previous,l1);
}
public double predict(double value){
if (prediction.containsKey(value)){
double total = prediction.get(value).get(0); //ERROR can't convert Object to double
Map items = prediction.get(value).get(1); //ERROR can't convert Object to Map
for (double i=0; i<=items.size();i++){ //iterate through Map
double a = items.get(i)/total; //ERROR can't divide object by double
}
}
}