2019-8-26 LinkedHashMap 转 Lis [tjava.util.LinkedHashMap cannot be cast to com.zq.dataservice.bean.Index]

java.util.LinkedHashMap cannot be cast to com.zq.dataservice.bean.Index

The above error is encountered when doing a trend of investment demo.

HashMap said that the chain can not be converted to a single object foreach

Its solution:

    private List<IndexData> map2IndexData(List<Map> temp) {
        List<IndexData> indexDatas = new ArrayList<>();
        for (Map map : temp) {
            String date = map.get("date").toString();
            float closePoint = Convert.toFloat(map.get("closePoint"));
            IndexData indexData = new IndexData();
            
            indexData.setDate(date);
            indexData.setClosePoint(closePoint);
            indexDatas.add(indexData);
        }
        
        return indexDatas;
    }
    private List<Index> map2Index(List<Map> temp) {
        List<Index> indexes = new ArrayList<>();
        for (Map map : temp) {
            String code = map.get("code").toString();
            String name = map.get("name").toString();
            Index index= new Index();
            index.setCode(code);
            index.setName(name);
            indexes.add(index);
        }

        return indexes;
    }

 

Guess you like

Origin www.cnblogs.com/ukzq/p/11411389.html